diff --git a/ion/include/ion.h b/ion/include/ion.h index 815a5e747..962968d23 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -16,7 +16,7 @@ void ion_app(); void ion_display_on(); void ion_display_off(); -void ion_sleep(); +void ion_sleep(long ms); /* CAUTION: This is a complete reset! */ void ion_reset(); diff --git a/ion/src/device/display.cpp b/ion/src/device/display.cpp index 1c87a7d74..74afb069f 100644 --- a/ion/src/device/display.cpp +++ b/ion/src/device/display.cpp @@ -2,10 +2,29 @@ #include "regs/regs.h" extern "C" { #include +#include } #define SEND_COMMAND(c, ...) {*CommandAddress = Command::c; uint8_t data[] = {__VA_ARGS__}; for (unsigned int i=0;isetGPIOCEN(true); + GPIOC.MODER()->setMODER(9, GPIO::MODER::MODE::Output); + GPIOC.ODR()->setODR(9, true); + + // Turn on the reset pin + RCC.AHB1ENR()->setGPIOBEN(true); + GPIOB.MODER()->setMODER(13, GPIO::MODER::MODE::Output); + GPIOB.ODR()->setODR(13, true); + + ion_sleep(120); + + Ion::Screen::initGPIO(); + Ion::Screen::initFSMC(); + Ion::Screen::initPanel(); +} + void Ion::Screen::initGPIO() { // We use GPIOA to GPIOD RCC.AHB1ENR()->setGPIOAEN(true); @@ -79,20 +98,13 @@ void Ion::Screen::initFSMC() { FSMC.BTR(4)->setBUSTURN(0); } -static inline void delayms(long ms) { - for (long i=0; i<1040*ms; i++) { - __asm volatile("nop"); - } -} - - void Ion::Screen::initPanel() { //*CommandAddress = 0x01; //software reset - //delayms(5); + //ion_sleep(5); *CommandAddress = Command::SleepOut; - delayms(120); + ion_sleep(120); SEND_COMMAND(PowerControlB, 0x00, 0x83, 0x30); SEND_COMMAND(PowerOnSequenceControl, 0x64, 0x03, 0x12, 0x81); @@ -114,28 +126,11 @@ void Ion::Screen::initPanel() { SEND_COMMAND(NegativeGammaCorrection, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3a, 0x78, 0x4d, 0x05, 0x18, 0x0d, 0x38, 0x3a, 0x1f); *CommandAddress = Command::SleepOut; //Exit Sleep - delayms(120); + ion_sleep(120); *CommandAddress = Command::DisplayOn; //Display on - delayms(50); + ion_sleep(50); } -void ion_screen_init() { - // Turn on the backlight - RCC.AHB1ENR()->setGPIOCEN(true); - GPIOC.MODER()->setMODER(9, GPIO::MODER::MODE::Output); - GPIOC.ODR()->setODR(9, true); - - // Turn on the reset pin - RCC.AHB1ENR()->setGPIOBEN(true); - GPIOB.MODER()->setMODER(13, GPIO::MODER::MODE::Output); - GPIOB.ODR()->setODR(13, true); - - delayms(120); - - Ion::Screen::initGPIO(); - Ion::Screen::initFSMC(); - Ion::Screen::initPanel(); -} void Ion::Screen::setDrawingArea(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { uint16_t x_start = x; diff --git a/ion/src/device/display.h b/ion/src/device/display.h index bb1e6502d..bec7cede1 100644 --- a/ion/src/device/display.h +++ b/ion/src/device/display.h @@ -2,7 +2,6 @@ extern "C" { #include #include #include - void ion_screen_init(); } /* Pinout: diff --git a/ion/src/device/init.c b/ion/src/device/init.cpp similarity index 78% rename from ion/src/device/init.c rename to ion/src/device/init.cpp index 518528593..25ec6a474 100644 --- a/ion/src/device/init.c +++ b/ion/src/device/init.cpp @@ -1,8 +1,11 @@ +extern "C" { +#include "init.h" #include #include -#include "init.h" #include "keyboard/keyboard.h" #include "registers/registers.h" +} +#include "display.h" void enable_fpu() { // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BABDBFBJ.html @@ -18,12 +21,14 @@ void enable_fpu() { void init_platform() { enable_fpu(); init_keyboard(); - ion_led_init(); - ion_screen_init(); + //ion_led_init(); + Ion::Screen::init(); } -void ion_sleep() { - // FIXME: Do something, and also move this function to its own file +void ion_sleep(long ms) { + for (long i=0; i<1040*ms; i++) { + __asm volatile("nop"); + } } void ion_reset() { diff --git a/ion/src/shared/events.c b/ion/src/shared/events.c index e48f13307..4e89ab459 100644 --- a/ion/src/shared/events.c +++ b/ion/src/shared/events.c @@ -19,9 +19,7 @@ static ion_key_event_t ion_get_key_event() { } // Wait a little to debounce the button. - // FIXME: REAL SLEEP - for (volatile int i=0;i<10000;i++) { - } + ion_sleep(10); /* Let's discard the keys we previously saw up but which aren't anymore: those * were probably bouncing! */ @@ -39,10 +37,7 @@ static ion_key_event_t ion_get_key_event() { key_seen_up[k] = 1; } } - ion_sleep(); - // FIXME: REAL SLEEP - for (int i=0;i<10000;i++) { - } + ion_sleep(10); } } diff --git a/ion/src/simulator/init.cpp b/ion/src/simulator/init.cpp index 65b2e9f0e..aed6f19de 100644 --- a/ion/src/simulator/init.cpp +++ b/ion/src/simulator/init.cpp @@ -79,8 +79,8 @@ bool ion_key_down(ion_key_t key) { return sKeyboard->key_down(key); } -void ion_sleep() { - usleep(1000); +void ion_sleep(long ms) { + usleep(1000*ms); sDisplay->redraw(); Fl::wait(); } diff --git a/quiz/src/runner.cpp b/quiz/src/runner.cpp index ae0f97ba5..df6b6e9e0 100644 --- a/quiz/src/runner.cpp +++ b/quiz/src/runner.cpp @@ -27,6 +27,6 @@ void ion_app() { } print("ALL TESTS FINISHED"); while (1) { - ion_sleep(); + ion_sleep(1000); } }