From b32b47300a14486f128cfc96e3ab8b7af68e554c Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Wed, 5 Aug 2015 15:52:44 +0200 Subject: [PATCH] ION re-structuring --- Makefile | 2 +- ion/Makefile | 2 +- ion/{src => }/drivers/fx92kbd/fx92kbd.c | 0 ion/{src => }/drivers/fx92kbd/fx92kbd.h | 0 ion/{src => }/drivers/ili9341/ili9341.c | 0 ion/{src => }/drivers/ili9341/ili9341.h | 0 ion/include/ion.h | 6 +--- ion/include/ion/framebuffer.h | 33 +++++++++++++++++++ ion/include/kandinsky_config.h | 5 +-- ion/{src => }/platform/simulator/Makefile | 0 ion/{src => }/platform/simulator/init.c | 0 ion/platform/stm32f429/Makefile | 2 ++ ion/{src => }/platform/stm32f429/display.c | 14 ++++---- ion/{src => }/platform/stm32f429/display.h | 0 ion/platform/stm32f429/framebuffer.h | 11 +++++++ ion/platform/stm32f429/init.c | 16 +++++++++ ion/{src => }/platform/stm32f429/init_heap.c | 0 ion/{src => }/platform/stm32f429/init_heap.h | 0 ion/{src => }/platform/stm32f429/init_kbd.c | 2 +- ion/{src => }/platform/stm32f429/init_kbd.h | 0 ion/{src => }/platform/stm32f429/platform.c | 0 ion/platform/stm32f429/platform.h | 14 ++++++++ .../platform/stm32f429/registers/gpio.h | 0 .../platform/stm32f429/registers/ltdc.h | 0 .../platform/stm32f429/registers/rcc.h | 0 .../platform/stm32f429/registers/registers.h | 0 .../platform/stm32f429/registers/spi.h | 0 ion/src/platform/stm32f429/Makefile | 2 -- ion/src/platform/stm32f429/init.c | 22 ------------- ion/src/platform/stm32f429/platform.h | 9 ----- kandinsky/include/kandinsky/color.h | 17 +++++++++- kandinsky/{src => include/kandinsky}/config.h | 14 ++------ kandinsky/include/kandinsky/referential.h | 5 +-- kandinsky/src/line.c | 2 +- kandinsky/src/referential.c | 2 +- 35 files changed, 114 insertions(+), 66 deletions(-) rename ion/{src => }/drivers/fx92kbd/fx92kbd.c (100%) rename ion/{src => }/drivers/fx92kbd/fx92kbd.h (100%) rename ion/{src => }/drivers/ili9341/ili9341.c (100%) rename ion/{src => }/drivers/ili9341/ili9341.h (100%) create mode 100644 ion/include/ion/framebuffer.h rename ion/{src => }/platform/simulator/Makefile (100%) rename ion/{src => }/platform/simulator/init.c (100%) create mode 100644 ion/platform/stm32f429/Makefile rename ion/{src => }/platform/stm32f429/display.c (96%) rename ion/{src => }/platform/stm32f429/display.h (100%) create mode 100644 ion/platform/stm32f429/framebuffer.h create mode 100644 ion/platform/stm32f429/init.c rename ion/{src => }/platform/stm32f429/init_heap.c (100%) rename ion/{src => }/platform/stm32f429/init_heap.h (100%) rename ion/{src => }/platform/stm32f429/init_kbd.c (98%) rename ion/{src => }/platform/stm32f429/init_kbd.h (100%) rename ion/{src => }/platform/stm32f429/platform.c (100%) create mode 100644 ion/platform/stm32f429/platform.h rename ion/{src => }/platform/stm32f429/registers/gpio.h (100%) rename ion/{src => }/platform/stm32f429/registers/ltdc.h (100%) rename ion/{src => }/platform/stm32f429/registers/rcc.h (100%) rename ion/{src => }/platform/stm32f429/registers/registers.h (100%) rename ion/{src => }/platform/stm32f429/registers/spi.h (100%) delete mode 100644 ion/src/platform/stm32f429/Makefile delete mode 100644 ion/src/platform/stm32f429/init.c delete mode 100644 ion/src/platform/stm32f429/platform.h rename kandinsky/{src => include/kandinsky}/config.h (62%) diff --git a/Makefile b/Makefile index 6de043e5e..8e39c4ab5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include Makefile.$(PLATFORM) ifndef USE_LIBA $(error Makefile.PLATFORM should define USE_LIBA) endif -SFLAGS += -DUSE_LIBA=$(USE_LIBA) +SFLAGS += -DPLATFORM=$(PLATFORM) -DUSE_LIBA=$(USE_LIBA) # Flags - Header search path SFLAGS += -Ilib -I. diff --git a/ion/Makefile b/ion/Makefile index dc4bb21d6..ed5da4e85 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -1,3 +1,3 @@ SFLAGS += -Iion/include -DKD_CONFIG_H=1 -include ion/src/platform/$(PLATFORM)/Makefile +include ion/platform/$(PLATFORM)/Makefile objs += $(addprefix ion/src/, ion.o) diff --git a/ion/src/drivers/fx92kbd/fx92kbd.c b/ion/drivers/fx92kbd/fx92kbd.c similarity index 100% rename from ion/src/drivers/fx92kbd/fx92kbd.c rename to ion/drivers/fx92kbd/fx92kbd.c diff --git a/ion/src/drivers/fx92kbd/fx92kbd.h b/ion/drivers/fx92kbd/fx92kbd.h similarity index 100% rename from ion/src/drivers/fx92kbd/fx92kbd.h rename to ion/drivers/fx92kbd/fx92kbd.h diff --git a/ion/src/drivers/ili9341/ili9341.c b/ion/drivers/ili9341/ili9341.c similarity index 100% rename from ion/src/drivers/ili9341/ili9341.c rename to ion/drivers/ili9341/ili9341.c diff --git a/ion/src/drivers/ili9341/ili9341.h b/ion/drivers/ili9341/ili9341.h similarity index 100% rename from ion/src/drivers/ili9341/ili9341.h rename to ion/drivers/ili9341/ili9341.h diff --git a/ion/include/ion.h b/ion/include/ion.h index 8ca589a87..f24170d21 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -2,17 +2,13 @@ #define ION_ION_H #include +#include void ion_init(); void ion_display_on(); void ion_display_off(); -extern void * ion_framebuffer_address; -extern uint16_t ion_framebuffer_width; -extern uint16_t ion_framebuffer_height; -extern uint8_t ion_framebuffer_bits_per_pixel; - char ion_getchar(); #endif diff --git a/ion/include/ion/framebuffer.h b/ion/include/ion/framebuffer.h new file mode 100644 index 000000000..774a7f6f0 --- /dev/null +++ b/ion/include/ion/framebuffer.h @@ -0,0 +1,33 @@ +#ifndef ION_FRAMEBUFFER_H +#define ION_FRAMEBUFFER_H + +/* This header doesn't do anything per-se. It only forward-includes the proper + * framebuffer.h file based on the PLATFORM variable, and checks that everything + * ION needs has been properly defined. */ + +#ifndef PLATFORM +#error ION expects PLATFORM to be defined +#endif + +#define QUOTE(x) QUOTE_1(x) +#define QUOTE_1(x) #x +#define FRAMEBUFFER_HEADER(x) QUOTE(../platform/x/framebuffer.h) +#include FRAMEBUFFER_HEADER(PLATFORM) + +#ifndef ION_FRAMEBUFFER_ADDRESS +#error PLATFORM/framebuffer.h should have defined ION_FRAMEBUFFER_ADDRESS +#endif + +#ifndef ION_FRAMEBUFFER_WIDTH +#error PLATFORM/framebuffer.h should have defined ION_FRAMEBUFFER_WIDTH +#endif + +#ifndef ION_FRAMEBUFFER_HEIGHT +#error PLATFORM/framebuffer.h should have defined ION_FRAMEBUFFER_HEIGHT +#endif + +#ifndef ION_FRAMEBUFFER_BITS_PER_PIXEL +#error PLATFORM/framebuffer.h should have defined ION_FRAMEBUFFER_BITS_PER_PIXEL +#endif + +#endif diff --git a/ion/include/kandinsky_config.h b/ion/include/kandinsky_config.h index 0de6a2c94..8cc8e1cab 100644 --- a/ion/include/kandinsky_config.h +++ b/ion/include/kandinsky_config.h @@ -1,3 +1,4 @@ #include -#define KD_FRAMEBUFFER_ADDRESS ion_framebuffer_address -#define KD_FRAMEBUFFER_WIDTH ion_framebuffer_width +#define KD_FRAMEBUFFER_ADDRESS ION_FRAMEBUFFER_ADDRESS +#define KD_FRAMEBUFFER_WIDTH ION_FRAMEBUFFER_WIDTH +#define KD_BITS_PER_PIXEL ION_FRAMEBUFFER_BITS_PER_PIXEL diff --git a/ion/src/platform/simulator/Makefile b/ion/platform/simulator/Makefile similarity index 100% rename from ion/src/platform/simulator/Makefile rename to ion/platform/simulator/Makefile diff --git a/ion/src/platform/simulator/init.c b/ion/platform/simulator/init.c similarity index 100% rename from ion/src/platform/simulator/init.c rename to ion/platform/simulator/init.c diff --git a/ion/platform/stm32f429/Makefile b/ion/platform/stm32f429/Makefile new file mode 100644 index 000000000..a3ba008e4 --- /dev/null +++ b/ion/platform/stm32f429/Makefile @@ -0,0 +1,2 @@ +objs += $(addprefix ion/platform/stm32f429/, platform.o init.o display.o init_kbd.o) +objs += $(addprefix ion/drivers/, ili9341/ili9341.o fx92kbd/fx92kbd.o) diff --git a/ion/src/platform/stm32f429/display.c b/ion/platform/stm32f429/display.c similarity index 96% rename from ion/src/platform/stm32f429/display.c rename to ion/platform/stm32f429/display.c index eb5f9cf54..75389a923 100644 --- a/ion/src/platform/stm32f429/display.c +++ b/ion/platform/stm32f429/display.c @@ -28,7 +28,7 @@ #include #include "platform.h" #include "registers/registers.h" -#include +#include void ion_display_on() { } @@ -183,11 +183,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 = ion_framebuffer_width; + int lcd_panel_hadr = ION_FRAMEBUFFER_WIDTH; int lcd_panel_hfp = 10; int lcd_panel_vsync = 2; int lcd_panel_vbp = 2; - int lcd_panel_vadr = ion_framebuffer_height; + int lcd_panel_vadr = ION_FRAMEBUFFER_HEIGHT; int lcd_panel_vfp = 4; // The LCD-TFT programmable synchronous timings are: @@ -268,13 +268,13 @@ static void init_rgb_layers() { LTDC_LPFCR(LTDC_LAYER1) = LTDC_PF_L8; - LTDC_LCFBAR(LTDC_LAYER1) = (uint32_t)ion_framebuffer_address; + LTDC_LCFBAR(LTDC_LAYER1) = (uint32_t)ION_FRAMEBUFFER_ADDRESS; LTDC_LCFBLR(LTDC_LAYER1) = - LTDC_CFBLL(ion_framebuffer_width + 3) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; - LTDC_CFBP(ion_framebuffer_width); // Width of a line in bytes + LTDC_CFBLL(ION_FRAMEBUFFER_WIDTH + 3) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; + LTDC_CFBP(ION_FRAMEBUFFER_WIDTH); // Width of a line in bytes - LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(ion_framebuffer_height); // Number of lines + LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(ION_FRAMEBUFFER_HEIGHT); // Number of lines // STEP 8 : Enable layer 1 // Don't enable color keying nor color look-up table diff --git a/ion/src/platform/stm32f429/display.h b/ion/platform/stm32f429/display.h similarity index 100% rename from ion/src/platform/stm32f429/display.h rename to ion/platform/stm32f429/display.h diff --git a/ion/platform/stm32f429/framebuffer.h b/ion/platform/stm32f429/framebuffer.h new file mode 100644 index 000000000..67788d4a9 --- /dev/null +++ b/ion/platform/stm32f429/framebuffer.h @@ -0,0 +1,11 @@ +#ifndef ION_STM32F429_FRAMEBUFFER_H +#define ION_STM32F429_FRAMEBUFFER_H + +extern char _framebuffer_start; + +#define ION_FRAMEBUFFER_ADDRESS (&_framebuffer_start) +#define ION_FRAMEBUFFER_WIDTH 240 +#define ION_FRAMEBUFFER_HEIGHT 320 +#define ION_FRAMEBUFFER_BITS_PER_PIXEL 16 + +#endif diff --git a/ion/platform/stm32f429/init.c b/ion/platform/stm32f429/init.c new file mode 100644 index 000000000..8fcd7cefd --- /dev/null +++ b/ion/platform/stm32f429/init.c @@ -0,0 +1,16 @@ +#include +#include +#include "display.h" +#include "init_kbd.h" + +extern char _framebuffer_end; + +void ion_init() { +#if DEBUG + char * computed_framebuffer_end = ION_FRAMEBUFFER_ADDRESS + (ION_FRAMEBUFFER_WIDTH*ION_FRAMEBUFFER_HEIGHT*ION_FRAMEBUFFER_BITS_PER_PIXEL)/8; + assert(&_framebuffer_end == computed_framebuffer_end); +#endif + + init_kbd(); + init_display(); +} diff --git a/ion/src/platform/stm32f429/init_heap.c b/ion/platform/stm32f429/init_heap.c similarity index 100% rename from ion/src/platform/stm32f429/init_heap.c rename to ion/platform/stm32f429/init_heap.c diff --git a/ion/src/platform/stm32f429/init_heap.h b/ion/platform/stm32f429/init_heap.h similarity index 100% rename from ion/src/platform/stm32f429/init_heap.h rename to ion/platform/stm32f429/init_heap.h diff --git a/ion/src/platform/stm32f429/init_kbd.c b/ion/platform/stm32f429/init_kbd.c similarity index 98% rename from ion/src/platform/stm32f429/init_kbd.c rename to ion/platform/stm32f429/init_kbd.c index 849139f77..87acb24b0 100644 --- a/ion/src/platform/stm32f429/init_kbd.c +++ b/ion/platform/stm32f429/init_kbd.c @@ -12,7 +12,7 @@ #include "platform.h" #include "registers/registers.h" #include "init_kbd.h" -#include +#include // The row pins are driven high or low in software. static gpio_pin_t row_pins[] = { diff --git a/ion/src/platform/stm32f429/init_kbd.h b/ion/platform/stm32f429/init_kbd.h similarity index 100% rename from ion/src/platform/stm32f429/init_kbd.h rename to ion/platform/stm32f429/init_kbd.h diff --git a/ion/src/platform/stm32f429/platform.c b/ion/platform/stm32f429/platform.c similarity index 100% rename from ion/src/platform/stm32f429/platform.c rename to ion/platform/stm32f429/platform.c diff --git a/ion/platform/stm32f429/platform.h b/ion/platform/stm32f429/platform.h new file mode 100644 index 000000000..a29f563d1 --- /dev/null +++ b/ion/platform/stm32f429/platform.h @@ -0,0 +1,14 @@ +#ifndef ION_STM32F429_PLATFORM_H +#define ION_STM32F429_PLATFORM_H + +#include +#include + +typedef struct { + ili9341_t display; + fx92kbd_t keyboard; +} platform_t; + +extern platform_t Platform; + +#endif diff --git a/ion/src/platform/stm32f429/registers/gpio.h b/ion/platform/stm32f429/registers/gpio.h similarity index 100% rename from ion/src/platform/stm32f429/registers/gpio.h rename to ion/platform/stm32f429/registers/gpio.h diff --git a/ion/src/platform/stm32f429/registers/ltdc.h b/ion/platform/stm32f429/registers/ltdc.h similarity index 100% rename from ion/src/platform/stm32f429/registers/ltdc.h rename to ion/platform/stm32f429/registers/ltdc.h diff --git a/ion/src/platform/stm32f429/registers/rcc.h b/ion/platform/stm32f429/registers/rcc.h similarity index 100% rename from ion/src/platform/stm32f429/registers/rcc.h rename to ion/platform/stm32f429/registers/rcc.h diff --git a/ion/src/platform/stm32f429/registers/registers.h b/ion/platform/stm32f429/registers/registers.h similarity index 100% rename from ion/src/platform/stm32f429/registers/registers.h rename to ion/platform/stm32f429/registers/registers.h diff --git a/ion/src/platform/stm32f429/registers/spi.h b/ion/platform/stm32f429/registers/spi.h similarity index 100% rename from ion/src/platform/stm32f429/registers/spi.h rename to ion/platform/stm32f429/registers/spi.h diff --git a/ion/src/platform/stm32f429/Makefile b/ion/src/platform/stm32f429/Makefile deleted file mode 100644 index ce0795890..000000000 --- a/ion/src/platform/stm32f429/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -objs += $(addprefix ion/src/platform/stm32f429/, platform.o init.o display.o init_kbd.o) -objs += $(addprefix ion/src/drivers/, ili9341/ili9341.o fx92kbd/fx92kbd.o) diff --git a/ion/src/platform/stm32f429/init.c b/ion/src/platform/stm32f429/init.c deleted file mode 100644 index 91bb9780d..000000000 --- a/ion/src/platform/stm32f429/init.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include "display.h" -#include "init_kbd.h" - -extern char _framebuffer_start; -extern char _framebuffer_end; - -void ion_init() { - ion_framebuffer_address = &_framebuffer_start; - ion_framebuffer_width = 240; - ion_framebuffer_height = 320; - ion_framebuffer_bits_per_pixel = 8; - -#if DEBUG - char * computed_framebuffer_end = ion_framebuffer_address + (ion_framebuffer_width*ion_framebuffer_height*ion_framebuffer_bits_per_pixel)/8; - assert(&_framebuffer_end == computed_framebuffer_end); -#endif - - init_kbd(); - init_display(); -} diff --git a/ion/src/platform/stm32f429/platform.h b/ion/src/platform/stm32f429/platform.h deleted file mode 100644 index e975ff406..000000000 --- a/ion/src/platform/stm32f429/platform.h +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -typedef struct { - ili9341_t display; - fx92kbd_t keyboard; -} platform_t; - -extern platform_t Platform; diff --git a/kandinsky/include/kandinsky/color.h b/kandinsky/include/kandinsky/color.h index 5612e65d2..a014f1f7c 100644 --- a/kandinsky/include/kandinsky/color.h +++ b/kandinsky/include/kandinsky/color.h @@ -2,7 +2,22 @@ #define KANDINSKY_COLOR_H #include -//FIXME: Should be configurable +#include + +#if KD_BITS_PER_PIXEL <= 8 +#warning KD_BITS_PER_PIXEL +#warning 8 bpp typedef uint8_t KDColor; +/* +#elif KD_BITS_PER_PIXEL <= 16 +typedef uint16_t KDColor; +#elif KD_BITS_PER_PIXEL <= 32 +typedef uint32_t KDColor; +#elif KD_BITS_PER_PIXEL <= 64 +typedef uint64_t KDColor; +*/ +#else +#error KD_BITS_PER_PIXEL is too large! +#endif #endif diff --git a/kandinsky/src/config.h b/kandinsky/include/kandinsky/config.h similarity index 62% rename from kandinsky/src/config.h rename to kandinsky/include/kandinsky/config.h index 2c9e6c84d..a6ac96850 100644 --- a/kandinsky/src/config.h +++ b/kandinsky/include/kandinsky/config.h @@ -13,16 +13,8 @@ #error Kandinsky expects KD_FRAMEBUFFER_WIDTH to be defined to the width of the framebuffer #endif -// FIXME: #define this -typedef uint8_t KDColor; - -/* -#include - -#define KD_FRAMEBUFFER_ADDRESS Platform.framebuffer_address -#define KD_FRAMEBUFFER_WIDTH Platform.framebuffer_width -typedef uint8_t KDColor; - -*/ +#ifndef KD_BITS_PER_PIXEL +#error Kandinsky expects KD_BITS_PER_PIXEL to be defined to the number of bits per pixels. +#endif #endif diff --git a/kandinsky/include/kandinsky/referential.h b/kandinsky/include/kandinsky/referential.h index 5ca3d23c2..a040b386e 100644 --- a/kandinsky/include/kandinsky/referential.h +++ b/kandinsky/include/kandinsky/referential.h @@ -7,8 +7,9 @@ void KDSetOrigin(KDPoint origin); KDPoint KDGetOrigin(); -KDColor * KDPixelAddress(KDPoint p); +void KDSetPixel(KDPoint p, KDColor c); -#define COLOR(p) *KDPixelAddress(p) +//KDColor * KDPixelAddress(KDPoint p); +//#define COLOR(p) *KDPixelAddress(p) #endif diff --git a/kandinsky/src/line.c b/kandinsky/src/line.c index 7767a2dda..2d64f0c73 100644 --- a/kandinsky/src/line.c +++ b/kandinsky/src/line.c @@ -3,6 +3,6 @@ void KDDrawLine(KDPoint p1, KDPoint p2) { for (KDCoordinate x = p1.x; x -#include "config.h" +#include static KDPoint sOrigin = {.x = 0, .y = 0};