From a7d3e8e6c9d3e92357784cf0579f4ba3d47f2beb Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Sun, 24 May 2015 21:42:49 +0200 Subject: [PATCH] Use a single Platform global --- platform/Makefile | 1 + platform/platform.c | 3 ++ platform/platform.h | 18 +++++++ platform/stm32f429/init_kbd.c | 99 +++++++++++++++++++++++++++++------ platform/stm32f429/init_kbd.h | 6 +++ platform/stm32f429/init_lcd.c | 44 +++++++++------- poincare/src/expression.cpp | 2 +- src/hello.cpp | 38 ++++++++++++++ 8 files changed, 175 insertions(+), 36 deletions(-) create mode 100644 platform/platform.c create mode 100644 platform/platform.h diff --git a/platform/Makefile b/platform/Makefile index ad46ecbbc..175277dc8 100644 --- a/platform/Makefile +++ b/platform/Makefile @@ -1,3 +1,4 @@ +objs += platform/platform.o objs += $(addprefix platform/stm32f429/, boot/isr.o boot/crt0.o init.o init_lcd.o init_heap.o init_kbd.o) objs += platform/ili9341/ili9341.o objs += platform/fx92kbd/fx92kbd.o diff --git a/platform/platform.c b/platform/platform.c new file mode 100644 index 000000000..046e34f43 --- /dev/null +++ b/platform/platform.c @@ -0,0 +1,3 @@ +#include "platform.h" + +platform_t Platform; diff --git a/platform/platform.h b/platform/platform.h new file mode 100644 index 000000000..41b668ba0 --- /dev/null +++ b/platform/platform.h @@ -0,0 +1,18 @@ +#ifndef PLATFORM_H +#define PLATFORM_H + +#include +#include + +typedef struct { + int framebuffer_width; + int framebuffer_height; + int framebuffer_bits_per_pixel; + char * framebuffer_address; + fx92kbd_t keyboard; + ili9341_t display; +} platform_t; + +extern platform_t Platform; + +#endif diff --git a/platform/stm32f429/init_kbd.c b/platform/stm32f429/init_kbd.c index a10728be8..f198bf2fd 100644 --- a/platform/stm32f429/init_kbd.c +++ b/platform/stm32f429/init_kbd.c @@ -10,7 +10,9 @@ #include #include #include "registers.h" +#include "init_kbd.h" #include +#include // The row pins are driven high or low in software. static gpio_pin_t row_pins[] = { @@ -45,17 +47,6 @@ static uint16_t column_read() { return output_value; } -static fx92kbd_t keyboard = { - .row_write = row_write, - .column_read = column_read -}; - -// FIXME: Delete -static int delay(int usec) { - for (int i=0; irow_write = row_write; + keyboard->column_read = column_read; - fx92kbd_key_t key = FX92_KEY_NONE; - while (1) { - key = fx92kbd_getkey(&keyboard); - } + fx92kbd_initialize(keyboard); +} + +char charFromKey[] = { + ' ', // FX92_KEY_NONE = 0 + ' ', // FX92_KEY_CUBE = 1, + ' ', // FX92_KEY_DOWN = 2, + ' ', + ' ', // FX92_KEY_SQUARE = 4, + ' ', // FX92_KEY_LEFT = 5, + ' ', // FX92_KEY_OPTN = 6, + ' ', + ' ', // FX92_KEY_TAN = 8, + ' ', // FX92_KEY_COS = 9, + ' ', // FX92_KEY_SIN = 10, + '0', // FX92_KEY_ZERO = 11, + ' ', // FX92_KEY_EUCLID = 12, + ' ', // FX92_KEY_FRAC = 13, + ' ', // FX92_KEY_SIMP = 14, + ' ', + ' ', + '/', // FX92_KEY_DIVISION = 17, + '*', // FX92_KEY_MULTIPLICATION = 18, + ' ', // FX92_KEY_REP = 19, + '5', // FX92_KEY_FIVE = 20, + '6', // FX92_KEY_SIX = 21, + '4', // FX92_KEY_FOUR = 22, + ' ', + ' ', + ' ', // FX92_KEY_AC = 25, + ' ', // FX92_KEY_SUPPR = 26, + ' ', // FX92_KEY_x10x = 27, + '8', // FX92_KEY_EIGHT = 28, + '9', // FX92_KEY_NINE = 29, + '7', // FX92_KEY_SEVEN = 30, + ' ', + ' ', + ' ', // FX92_KEY_MENU = 33, + ' ', // FX92_KEY_RIGHT = 34, + ' ', + ' ', // FX92_KEY_ALPHA = 36, + ' ', // FX92_KEY_UP = 37, + ' ', // FX92_KEY_SECOND = 38, + ' ', + ' ', + '-', // FX92_KEY_MINUS = 41, + '+', // FX92_KEY_PLUS = 42, + 'X', // FX92_KEY_EXE = 43, + '2', // FX92_KEY_TWO = 44, + '3', // FX92_KEY_THREE = 45, + '1', // FX92_KEY_ONE = 46, + ' ', + ' ', // FX92_KEY_M_PLUS = 48, + ' ', // FX92_KEY_S_D = 49, + ' ', // FX92_KEY_PAREN_RIGHT = 50, + ' ', // FX92_KEY_COMMA = 51, + ' ', // FX92_KEY_DMS = 52, + ' ', // FX92_KEY_PAREN_LEFT = 53, + ' ', // FX92_KEY_STO = 54, + ' ', + ' ', // FX92_KEY_LN = 56, + ' ', // FX92_KEY_LOG = 57, + ' ', // FX92_KEY_X = 58, + ' ', + ' ', // FX92_KEY_Y = 60, + ' ', // FX92_KEY_EQUAL = 61, + ' ', // FX92_KEY_CALC = 62, + ' ', // FX92_KEY_EXPONENT = 0, + ' ', // FX92_KEY_NONE = 0, +}; + +char getc() { + char character = ' '; + while (character == ' ') { + fx92kbd_key_t key = fx92kbd_getkey(&Platform.keyboard); + character = charFromKey[key]; + } + return character; } diff --git a/platform/stm32f429/init_kbd.h b/platform/stm32f429/init_kbd.h index 5d0176349..e31d38616 100644 --- a/platform/stm32f429/init_kbd.h +++ b/platform/stm32f429/init_kbd.h @@ -1 +1,7 @@ +#ifndef STM32F429_KBD_H +#define STM32F429_KBD_H + void init_kbd(); +char getc(); + +#endif diff --git a/platform/stm32f429/init_lcd.c b/platform/stm32f429/init_lcd.c index f3d9a98fe..818522bf9 100644 --- a/platform/stm32f429/init_lcd.c +++ b/platform/stm32f429/init_lcd.c @@ -21,6 +21,8 @@ * therefore extended registers are not available. Those are 0xB0-0xCF and 0xE0 * - 0xFF. Apparently this means we cannot read the display ID (RDDIDIF). * That's wat ST says in stm32f429i_discovery_lcd.c. + * + * It doesn't seem right though, because some extended commands do work... */ /*#include "registers/rcc.h" @@ -30,6 +32,7 @@ #include #include "registers.h" #include "framebuffer.h" +#include #include extern pixel_t _framebuffer_start; @@ -46,6 +49,11 @@ void init_lcd() { * this routine, everyone can expect to write to the LCD by writing to the * framebuffer. */ + Platform.framebuffer_width = 240; + Platform.framebuffer_height = 320; + Platform.framebuffer_bits_per_pixel = 8; + Platform.framebuffer_address = &_framebuffer_start; + init_spi_interface(); init_rgb_interface(); @@ -111,13 +119,14 @@ static void init_rgb_interface() { } +// FIXME: Apparently many of those aren't needed. E.g the GPIOE ones gpio_pin_t rgb_pins[] = { {GPIOA, 3}, {GPIOA, 4}, {GPIOA, 6}, {GPIOA, 8}, {GPIOA, 11}, {GPIOA, 12}, {GPIOB, 8}, {GPIOB, 9}, {GPIOB, 10}, {GPIOB, 11}, {GPIOC, 6}, {GPIOC, 7}, {GPIOC, 10}, {GPIOD, 3}, {GPIOD, 6}, {GPIOD, 10}, - {GPIOE, 4}, {GPIOE, 5}, {GPIOE, 6}, {GPIOE, 11}, {GPIOE, 12}, {GPIOE, 13}, - {GPIOE, 14}, {GPIOE, 15}, + //{GPIOE, 4}, {GPIOE, 5}, {GPIOE, 6}, {GPIOE, 11}, {GPIOE, 12}, {GPIOE, 13}, + //{GPIOE, 14}, {GPIOE, 15}, {GPIOF, 10}, {GPIOG, 6}, {GPIOG, 7}, {GPIOG, 10}, {GPIOG, 11}, {GPIOG, 12}, {GPIOH, 2}, {GPIOH, 3}, {GPIOH, 8}, {GPIOH, 9}, {GPIOH, 10}, {GPIOH, 11}, @@ -148,7 +157,7 @@ static void init_rgb_gpios() { } //FIXME: Apprently DMA should be enabled? - RCC_AHB1ENR |= (DMA1EN | DMA2EN | DMA2DEN); + //RCC_AHB1ENR |= (DMA1EN | DMA2EN | DMA2DEN); } static void init_rgb_clocks() { @@ -192,7 +201,6 @@ static void init_rgb_clocks() { } } - static void init_rgb_timings() { // Configure the Synchronous timings: VSYNC, HSYNC, Vertical and Horizontal // back porch, active data area and the front porch timings following the @@ -202,11 +210,11 @@ static void init_rgb_timings() { // seems to match our hardware. Here are the values of interest: int lcd_panel_hsync = 10; int lcd_panel_hbp = 20; - int lcd_panel_hadr = 240; + int lcd_panel_hadr = Platform.framebuffer_width; int lcd_panel_hfp = 10; int lcd_panel_vsync = 2; int lcd_panel_vbp = 2; - int lcd_panel_vadr = 320; + int lcd_panel_vadr = Platform.framebuffer_height; int lcd_panel_vfp = 4; // The LCD-TFT programmable synchronous timings are: @@ -287,13 +295,13 @@ static void init_rgb_layers() { LTDC_LPFCR(LTDC_LAYER1) = LTDC_PF_L8; - LTDC_LCFBAR(LTDC_LAYER1) = (uint32_t)(&_framebuffer_start); + LTDC_LCFBAR(LTDC_LAYER1) = Platform.framebuffer_address; LTDC_LCFBLR(LTDC_LAYER1) = - LTDC_CFBLL(243) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; - LTDC_CFBP(240); // Width of a line in bytes + LTDC_CFBLL(Platform.framebuffer_width + 3) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; + LTDC_CFBP(Platform.framebuffer_width); // Width of a line in bytes - LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(320); // Number of lines + LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(Platform.framebuffer_height); // Number of lines // STEP 8 : Enable layer 1 // Don't enable color keying nor color look-up table @@ -315,14 +323,12 @@ static void spi_5_write(char * data, size_t size); static void gpio_c2_write(bool pin_state); static void gpio_d13_write(bool pin_state); -static ili9341_t panel = { - .chip_select_pin_write = gpio_c2_write, - .data_command_pin_write = gpio_d13_write, - .spi_write = spi_5_write -}; - static void init_panel() { - ili9341_initialize(&panel); + ili9341_t * panel = &(Platform.display); + panel->chip_select_pin_write = gpio_c2_write; + panel->data_command_pin_write = gpio_d13_write; + panel->spi_write = spi_5_write; + ili9341_initialize(panel); } static void spi_5_write(char * data, size_t size) { @@ -348,8 +354,8 @@ void gpio_d13_write(bool pin_state) { // Framebuffer checks static void check_framebuffer() { - assert(&_framebuffer_start == FRAMEBUFFER_ADDRESS); - pixel_t * fb_end = &_framebuffer_start + (FRAMEBUFFER_WIDTH*FRAMEBUFFER_HEIGHT*FRAMEBUFFER_BITS_PER_PIXEL)/8; + assert(&_framebuffer_start == Platform.framebuffer_address); + pixel_t * fb_end = &_framebuffer_start + (Platform.framebuffer_width*Platform.framebuffer_height*Platform.framebuffer_bits_per_pixel/8); assert(&_framebuffer_end == fb_end); assert(8*sizeof(pixel_t) == FRAMEBUFFER_BITS_PER_PIXEL); } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 85ef379f3..a164357ac 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -16,7 +16,7 @@ void CreateFromString(char * string) { expression->recursiveLayout(); - expression->m_frame.origin = KDPOINT(0, 0); + expression->m_frame.origin = KDPOINT(0, 100); expression->recursiveDraw(); poincare_expression_yy_delete_buffer(buf, scanner); diff --git a/src/hello.cpp b/src/hello.cpp index eac4eeab4..268529d3d 100644 --- a/src/hello.cpp +++ b/src/hello.cpp @@ -2,11 +2,20 @@ extern "C" { #include "hello.h" #include #include +#include } #include + void hello() { + + /*char letter = 'Z'; + while (1) { + letter = getc(); + } + */ + KDFillRect((KDRect){ .x = 0, .y = 0, @@ -20,6 +29,8 @@ void hello() { KDDrawString("Hello, world", (KDPoint){}); */ + /* + Number n1 = Number(123); Number n2 = Number(45); @@ -38,7 +49,34 @@ void hello() { free(bar); free(test); + */ +/* + while (1) { + char character = getc(); + KDDrawChar(character, (KDPoint){.x = 0, .y = 0}); + } + */ + char input[255]; + + int index = 0; + while (1) { + char character = getc(); + if (character == 'X') { + input[index] = 0; + index = 0; + CreateFromString(input); + } else { + input[index++] = character; + input[index] = 0; + KDDrawString(input, (KDPoint){.x = 0, .y = 0}); + } + } + + /* + char * input = "12/34/8787/29292929"; + CreateFromString(input); +*/ }