2011-05-20 22:01:53 +00:00
|
|
|
#include "basic.h"
|
|
|
|
#include "core/gpio/gpio.h"
|
2011-07-16 17:12:35 +00:00
|
|
|
#include "lcd/backlight.c"
|
|
|
|
#include "lcd/render.h"
|
2011-07-18 16:19:22 +00:00
|
|
|
#include "lcd/fonts/smallfonts.h"
|
2011-07-16 17:12:35 +00:00
|
|
|
#include "ecc.h"
|
2011-05-20 22:01:53 +00:00
|
|
|
|
|
|
|
void rbInit() {
|
|
|
|
// TODO FIXME special port disable ? LEDs BTNs ?
|
|
|
|
|
|
|
|
// prepare power
|
|
|
|
// TODO FIXME more power init needed ? chrg + volt input ?
|
|
|
|
// enable external vcc
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_PWR_GOOD, gpioDirection_Output);
|
|
|
|
gpioSetValue (RB_PWR_GOOD, 0);
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-06-13 21:09:37 +00:00
|
|
|
// Disable USB Connect (we don't want USB by default)
|
|
|
|
gpioSetDir(USB_CONNECT, gpioDirection_Output);
|
|
|
|
gpioSetValue(USB_CONNECT, 1);
|
2011-05-20 22:01:53 +00:00
|
|
|
|
|
|
|
// prepare buttons
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_BTN0, gpioDirection_Input);
|
2011-05-20 22:01:53 +00:00
|
|
|
gpioSetPullup (&RB_BTN0_IO, gpioPullupMode_PullUp);
|
|
|
|
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_BTN1, gpioDirection_Input);
|
2011-05-20 22:01:53 +00:00
|
|
|
gpioSetPullup (&RB_BTN1_IO, gpioPullupMode_PullUp);
|
|
|
|
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_BTN2, gpioDirection_Input);
|
2011-05-20 22:01:53 +00:00
|
|
|
gpioSetPullup (&RB_BTN2_IO, gpioPullupMode_PullUp);
|
|
|
|
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_BTN3, gpioDirection_Input);
|
2011-05-20 22:01:53 +00:00
|
|
|
gpioSetPullup (&RB_BTN3_IO, gpioPullupMode_PullUp);
|
|
|
|
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_BTN4, gpioDirection_Input);
|
2011-05-20 22:01:53 +00:00
|
|
|
gpioSetPullup (&RB_BTN4_IO, gpioPullupMode_PullUp);
|
|
|
|
|
2011-07-31 20:13:06 +00:00
|
|
|
// prepate chrg_stat
|
|
|
|
gpioSetDir(RB_PWR_CHRG, gpioDirection_Input);
|
|
|
|
gpioSetPullup (&RB_PWR_CHRG_IO, gpioPullupMode_PullUp);
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-12-19 20:21:07 +00:00
|
|
|
gpioSetDir(RB_LED3, gpioDirection_Input);
|
|
|
|
IOCON_PIO1_11 = 0x41;
|
|
|
|
|
|
|
|
|
2011-05-20 22:01:53 +00:00
|
|
|
// prepare LEDs
|
2011-06-12 20:54:41 +00:00
|
|
|
IOCON_JTAG_TDI_PIO0_11 &= ~IOCON_JTAG_TDI_PIO0_11_FUNC_MASK;
|
|
|
|
IOCON_JTAG_TDI_PIO0_11 |= IOCON_JTAG_TDI_PIO0_11_FUNC_GPIO;
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-12-19 20:21:07 +00:00
|
|
|
uint8_t ports[] = { RB_LED0, RB_LED1, RB_LED2,
|
2011-12-18 03:11:47 +00:00
|
|
|
RB_SPI_SS0, RB_SPI_SS1, RB_SPI_SS2,
|
|
|
|
RB_SPI_SS3, RB_SPI_SS4, RB_SPI_SS5,
|
|
|
|
RB_HB0, RB_HB1, RB_HB2,
|
|
|
|
RB_HB3, RB_HB4, RB_HB5};
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-12-18 03:11:47 +00:00
|
|
|
int i = 0;
|
|
|
|
while( i<8 ){
|
|
|
|
gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
|
2011-12-19 19:59:03 +00:00
|
|
|
gpioSetValue (ports[i], ports[i+1], 0);
|
|
|
|
i+=2;
|
2011-12-18 03:11:47 +00:00
|
|
|
}
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-08-04 12:53:13 +00:00
|
|
|
// Set LED3 to ?
|
2011-06-12 23:03:52 +00:00
|
|
|
IOCON_PIO1_11 = 0x41;
|
2011-05-20 22:01:53 +00:00
|
|
|
|
|
|
|
// prepare lcd
|
|
|
|
// TODO FIXME more init needed ?
|
2011-05-20 22:31:58 +00:00
|
|
|
gpioSetDir(RB_LCD_BL, gpioDirection_Output);
|
2011-06-12 20:54:41 +00:00
|
|
|
gpioSetValue (RB_LCD_BL, 0);
|
2011-05-20 22:01:53 +00:00
|
|
|
|
2011-06-12 20:54:41 +00:00
|
|
|
// Set P0.0 to GPIO
|
|
|
|
RB_PWR_LCDBL_IO&= ~RB_PWR_LCDBL_IO_FUNC_MASK;
|
|
|
|
RB_PWR_LCDBL_IO|= RB_PWR_LCDBL_IO_FUNC_GPIO;
|
|
|
|
gpioSetDir(RB_PWR_LCDBL, gpioDirection_Input);
|
|
|
|
gpioSetPullup(&RB_PWR_LCDBL_IO, gpioPullupMode_Inactive);
|
2011-05-20 22:01:53 +00:00
|
|
|
|
|
|
|
// prepare I2C
|
|
|
|
#ifdef __I2C_h
|
|
|
|
i2cInit(I2CMASTER); // TODO FIXME via define ?
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// prepare SPI/SS
|
2011-12-18 03:11:47 +00:00
|
|
|
// TODO FIXME init miso/mosi/sck somehow ?
|
2011-05-20 22:01:53 +00:00
|
|
|
// prepare hackerbus
|
2011-12-18 03:11:47 +00:00
|
|
|
while(i<sizeof(ports)){
|
|
|
|
gpioSetDir(ports[i],ports[i+1], gpioDirection_Output);
|
2011-12-19 19:59:03 +00:00
|
|
|
gpioSetValue (ports[i], ports[i+1], 1);
|
|
|
|
i+=2;
|
2011-12-18 03:11:47 +00:00
|
|
|
}
|
2011-05-20 22:01:53 +00:00
|
|
|
|
|
|
|
// prepare BUSINT interrupt
|
2011-08-05 21:34:52 +00:00
|
|
|
//gpioSetDir(RB_BUSINT, gpioDirection_Input);
|
|
|
|
//gpioSetPullup (&RB_BUSINT_IO, gpioPullupMode_PullUp);
|
|
|
|
//gpioSetInterrupt(RB_BUSINT, gpioInterruptSense_Edge, gpioInterruptEdge_Single, gpioInterruptEvent_ActiveLow);
|
|
|
|
//gpioIntEnable(RB_BUSINT);
|
2011-07-16 17:12:35 +00:00
|
|
|
|
|
|
|
//nrf_init();
|
|
|
|
backlightInit();
|
|
|
|
font=&Font_7x8;
|
|
|
|
ECIES_setup();
|
2011-05-20 22:01:53 +00:00
|
|
|
}
|
2011-08-04 12:53:13 +00:00
|
|
|
|
2011-07-23 19:47:29 +00:00
|
|
|
#define WEAK_ALIAS(f) __attribute__ ((weak, alias (#f)));
|
|
|
|
void interrupt_undefined(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void businterrupt(void) WEAK_ALIAS(interrupt_undefined);
|
|
|
|
|
|
|
|
|
|
|
|
void PIOINT3_IRQHandler(void) {
|
|
|
|
if (gpioIntStatus(RB_BUSINT)) {
|
|
|
|
gpioIntClear(RB_BUSINT);
|
|
|
|
businterrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|