mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Use a single Platform global
This commit is contained in:
@@ -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
|
||||
|
||||
3
platform/platform.c
Normal file
3
platform/platform.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "platform.h"
|
||||
|
||||
platform_t Platform;
|
||||
18
platform/platform.h
Normal file
18
platform/platform.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include <platform/fx92kbd/fx92kbd.h>
|
||||
#include <platform/ili9341/ili9341.h>
|
||||
|
||||
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
|
||||
@@ -10,7 +10,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "registers.h"
|
||||
#include "init_kbd.h"
|
||||
#include <platform/fx92kbd/fx92kbd.h>
|
||||
#include <platform/platform.h>
|
||||
|
||||
// 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; i<usec; i++) {
|
||||
}
|
||||
}
|
||||
|
||||
void init_kbd() {
|
||||
// We are using group E. Let's enable its clock.
|
||||
RCC_AHB1ENR |= GPIOEEN;
|
||||
@@ -76,10 +67,86 @@ void init_kbd() {
|
||||
REGISTER_SET_VALUE(GPIO_PUPDR(pin.group), PUPDR(pin.number), GPIO_PUPD_PULL_DOWN);
|
||||
}
|
||||
|
||||
fx92kbd_initialize(&keyboard);
|
||||
fx92kbd_t * keyboard = &(Platform.keyboard);
|
||||
keyboard->row_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;
|
||||
}
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
#ifndef STM32F429_KBD_H
|
||||
#define STM32F429_KBD_H
|
||||
|
||||
void init_kbd();
|
||||
char getc();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#include "registers.h"
|
||||
#include "framebuffer.h"
|
||||
#include <platform/platform.h>
|
||||
#include <platform/ili9341/ili9341.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2,11 +2,20 @@ extern "C" {
|
||||
#include "hello.h"
|
||||
#include <kandinsky.h>
|
||||
#include <malloc.h>
|
||||
#include <platform/stm32f429/init_kbd.h>
|
||||
}
|
||||
|
||||
#include <poincare.h>
|
||||
|
||||
|
||||
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);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user