X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/9d18e10afb2439a6a9ba6978a799259746a837b7..HEAD:/sysinit.c diff --git a/sysinit.c b/sysinit.c index 60b4d3b..0385a21 100644 --- a/sysinit.c +++ b/sysinit.c @@ -39,12 +39,12 @@ #include #include #include +#include #include "sysinit.h" #include "core/cpu/cpu.h" #include "core/pmu/pmu.h" -#include "core/adc/adc.h" #ifdef CFG_PRINTF_UART #include "core/uart/uart.h" @@ -55,7 +55,7 @@ #endif #ifdef CFG_CHIBI - #include "drivers/chibi/chb.h" + #include "drivers/rf/chibi/chb.h" #endif #ifdef CFG_USBHID @@ -72,24 +72,24 @@ #endif #ifdef CFG_ST7565 - #include "drivers/lcd/bitmap/st7565/st7565.h" - #include "drivers/lcd/smallfonts.h" + #include "drivers/displays/bitmap/st7565/st7565.h" + #include "drivers/displays/smallfonts.h" #endif #ifdef CFG_SSD1306 - #include "drivers/lcd/bitmap/ssd1306/ssd1306.h" - #include "drivers/lcd/smallfonts.h" + #include "drivers/displays/bitmap/ssd1306/ssd1306.h" + #include "drivers/displays/smallfonts.h" #endif #ifdef CFG_TFTLCD - #include "drivers/lcd/tft/lcd.h" - #include "drivers/lcd/tft/touchscreen.h" - #include "drivers/lcd/tft/drawing.h" + #include "drivers/displays/tft/lcd.h" + #include "drivers/displays/tft/touchscreen.h" + #include "drivers/displays/tft/drawing.h" #endif #ifdef CFG_I2CEEPROM - #include "drivers/eeprom/mcp24aa/mcp24aa.h" - #include "drivers/eeprom/eeprom.h" + #include "drivers/storage/eeprom/mcp24aa/mcp24aa.h" + #include "drivers/storage/eeprom/eeprom.h" #endif #ifdef CFG_PWM @@ -103,8 +103,16 @@ DWORD get_fattime () { - // ToDo! - return 0; + DWORD tmr = 0; + + // tmr = (((DWORD)rtcYear - 80) << 25) + // | ((DWORD)rtcMon << 21) + // | ((DWORD)rtcMday << 16) + // | (WORD)(rtcHour << 11) + // | (WORD)(rtcMin << 5) + // | (WORD)(rtcSec >> 1); + + return tmr; } #endif @@ -124,12 +132,18 @@ void systemInit() systickInit(CFG_SYSTICK_DELAY_IN_MS); // Start systick timer gpioInit(); // Enable GPIO pmuInit(); // Configure power management - adcInit(); // Config adc pins to save power // Set LED pin as output and turn LED off gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 1); gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); + // Config alt reset pin if requested (really only relevant to LPC1343 LCD Board) + #ifdef CFG_ALTRESET + gpioSetDir (CFG_ALTRESET_PORT, CFG_ALTRESET_PIN, gpioDirection_Input); + gpioSetInterrupt (CFG_ALTRESET_PORT, CFG_ALTRESET_PIN, gpioInterruptSense_Level, gpioInterruptEdge_Single, gpioInterruptEvent_ActiveHigh); + gpioIntEnable (CFG_ALTRESET_PORT, CFG_ALTRESET_PIN); + #endif + // Initialise EEPROM #ifdef CFG_I2CEEPROM mcp24aaInit(); @@ -137,15 +151,19 @@ void systemInit() // Initialise UART with the default baud rate #ifdef CFG_PRINTF_UART - uint32_t uart = eepromReadU32(CFG_EEPROM_UART_SPEED); - if ((uart == 0xFFFFFFFF) || (uart > 115200)) - { - uartInit(CFG_UART_BAUDRATE); // Use default baud rate - } - else - { - uartInit(uart); // Use baud rate from EEPROM - } + #ifdef CFG_I2CEEPROM + uint32_t uart = eepromReadU32(CFG_EEPROM_UART_SPEED); + if ((uart == 0xFFFFFFFF) || (uart > 115200)) + { + uartInit(CFG_UART_BAUDRATE); // Use default baud rate + } + else + { + uartInit(uart); // Use baud rate from EEPROM + } + #else + uartInit(CFG_UART_BAUDRATE); + #endif #endif // Initialise PWM (requires 16-bit Timer 1 and P1.9) @@ -185,13 +203,26 @@ void systemInit() // Initialise the SSD1306 OLED display #ifdef CFG_SSD1306 - ssd1306Init(SSD1306_SWITCHCAPVCC); + ssd1306Init(SSD1306_INTERNALVCC); ssd1306ClearScreen(); // Clear the screen #endif // Initialise TFT LCD Display #ifdef CFG_TFTLCD lcdInit(); + // You may need to call the tsCalibrate() function to calibrate + // the touch screen is this has never been done. This only needs + // to be done once and the values are saved to EEPROM. This + // function can also be called from tsInit if it's more + // convenient + /* + #ifdef CFG_I2CEEPROM + if (eepromReadU8(CFG_EEPROM_TOUCHSCREEN_CALIBRATED) != 1) + { + tsCalibrate(); + } + #endif + */ #endif // Initialise Chibi @@ -276,3 +307,61 @@ int puts(const char * str) return 0; } + +// Override printf here if we're using Crossworks for ARM +// so that we can still use the custom libc libraries. +// For Codelite and compiling from the makefile (Yagarto, etc.) +// this is done in /core/libc + +#ifdef __CROSSWORKS_ARM + +/**************************************************************************/ +/*! + @brief Outputs a formatted string on the DBGU stream. Format arguments + are given in a va_list instance. + + @param[in] pFormat + Format string + @param[in] ap + Argument list +*/ +/**************************************************************************/ +signed int vprintf(const char *pFormat, va_list ap) +{ + char pStr[CFG_PRINTF_MAXSTRINGSIZE]; + char pError[] = "stdio.c: increase CFG_PRINTF_MAXSTRINGSIZE\r\n"; + + // Write formatted string in buffer + if (vsprintf(pStr, pFormat, ap) >= CFG_PRINTF_MAXSTRINGSIZE) { + + puts(pError); + while (1); // Increase CFG_PRINTF_MAXSTRINGSIZE + } + + // Display string + return puts(pStr); +} + +/**************************************************************************/ +/*! + @brief Outputs a formatted string on the DBGU stream, using a + variable number of arguments + + @param[in] pFormat + Format string +*/ +/**************************************************************************/ +signed int printf(const char *pFormat, ...) +{ + va_list ap; + signed int result; + + // Forward call to vprintf + va_start(ap, pFormat); + result = vprintf(pFormat, ap); + va_end(ap); + + return result; +} + +#endif