[ion] Clean ion_sleep

Change-Id: Ib71e7e535ecd2ee572d09f2e64f2cba9368c614f
This commit is contained in:
Romain Goyet
2016-08-18 16:24:50 +02:00
parent 809fdfdfab
commit 2eeec9e929
7 changed files with 39 additions and 45 deletions

View File

@@ -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();

View File

@@ -2,10 +2,29 @@
#include "regs/regs.h"
extern "C" {
#include <assert.h>
#include <ion.h>
}
#define SEND_COMMAND(c, ...) {*CommandAddress = Command::c; uint8_t data[] = {__VA_ARGS__}; for (unsigned int i=0;i<sizeof(data);i++) { *DataAddress = data[i];};}
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);
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;

View File

@@ -2,7 +2,6 @@ extern "C" {
#include <ion/screen.h>
#include <stdint.h>
#include <string.h>
void ion_screen_init();
}
/* Pinout:

View File

@@ -1,8 +1,11 @@
extern "C" {
#include "init.h"
#include <ion.h>
#include <assert.h>
#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() {

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -27,6 +27,6 @@ void ion_app() {
}
print("ALL TESTS FINISHED");
while (1) {
ion_sleep();
ion_sleep(1000);
}
}