LCD driver is fixed (in a crappy way)

* fixed weird bug in lcd driver
+ imported graphs for the thermistor
* updated linker file to better fit the device used (more to be done)
This commit is contained in:
Steins7 2020-01-29 21:50:45 +01:00
parent 64b8265e90
commit 5e65b9156a
6 changed files with 108 additions and 36 deletions

View File

@ -4,7 +4,7 @@
# --- control global project settings # --- control global project settings
# RELEASE=1 -> enable optimisation, then disable debug # RELEASE=1 -> enable optimisation, then disable debug
# RELEASE=0 -> disbale optimisation, then enable debug # RELEASE=0 -> disbale optimisation, then enable debug
RELEASE=0 RELEASE=1
# --- project architecture # --- project architecture
# program name # program name

Binary file not shown.

View File

@ -6,7 +6,11 @@ enum mode {
UNDEFINED UNDEFINED
}; };
static int mode = UNDEFINED; //TODO make the driver dynamic ?
static TIM_TypeDef* timer = 0;
static uint8_t mode = UNDEFINED;
static uint8_t rows = 0;
static uint8_t columns = 0;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// internal functions // internal functions
@ -39,18 +43,19 @@ int set_mode_write(void) {
} }
void wait_for_ready(void) { void wait_for_ready(void) {
// configure the lcd //TODO debug that
if(mode != READ) if(set_mode_read()) return; // // configure the lcd
// if(mode != READ) if(set_mode_read()) return;
// read D7 pin //
for(;;) { // // read D7 pin
io_set(GPIOA, PIN_11); // for(;;) {
for(int i=0; i<1000; ++i); //timer_wait is overkill here // io_set(GPIOA, PIN_11);
if(!io_read(GPIOB, PIN_4)) break; // for(int i=0; i<1000; ++i); //timer_wait is overkill here
io_clear(GPIOA, PIN_11); // if(!io_read(GPIOB, PIN_4)) break;
for(int i=0; i<1000; ++i); //same // io_clear(GPIOA, PIN_11);
} // for(int i=0; i<1000; ++i); //same
io_clear(GPIOA, PIN_11); // }
timer_wait_ms(timer, 2, 0); //wait max delay
} }
void write_byte(uint8_t byte) { void write_byte(uint8_t byte) {
@ -59,7 +64,7 @@ void write_byte(uint8_t byte) {
// start tranfert // start tranfert
io_set(GPIOA, PIN_11); io_set(GPIOA, PIN_11);
timer_wait_us(TIM1, 1, 0); timer_wait_us(timer, 1, 0);
// send the data // send the data
io_write(GPIOA, (byte >> 0) & 0x1, PIN_8); io_write(GPIOA, (byte >> 0) & 0x1, PIN_8);
@ -76,8 +81,12 @@ void write_byte(uint8_t byte) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// API functions int lcd_init(TIM_TypeDef* tim, uint8_t col, uint8_t row) {
int lcd_init(TIM_TypeDef* tim) {
timer = tim;
columns = col;
rows = row;
// disable JTAG, as it utilise needed pins, SWD remains usable in // disable JTAG, as it utilise needed pins, SWD remains usable in
// synchronous mode // synchronous mode
RCC->APB2ENR |= 0x1; RCC->APB2ENR |= 0x1;
@ -91,17 +100,17 @@ int lcd_init(TIM_TypeDef* tim) {
if(set_mode_write()) return -1; //no check in case the pins were used if(set_mode_write()) return -1; //no check in case the pins were used
//somewhere else //somewhere else
// select instrution register // select instruction register
io_write(GPIOA, LCD_MODE_CMD, PIN_10); io_write(GPIOA, LCD_MODE_CMD, PIN_10);
// begin initialisation sequence // begin initialisation sequence
timer_wait_ms(tim, 15, 0); timer_wait_ms(timer, 15, 0);
write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE | write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE |
LCD_FUNC_5x8DOTS); LCD_FUNC_5x8DOTS);
timer_wait_ms(tim, 5, 0); timer_wait_ms(timer, 5, 0);
write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE | write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE |
LCD_FUNC_5x8DOTS); LCD_FUNC_5x8DOTS);
timer_wait_us(tim, 150, 0); timer_wait_us(timer, 150, 0);
write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE | write_byte(LCD_FUNC_SET | LCD_FUNC_8BIT | LCD_FUNC_2LINE |
LCD_FUNC_5x8DOTS); LCD_FUNC_5x8DOTS);
wait_for_ready(); wait_for_ready();
@ -121,7 +130,39 @@ int lcd_init(TIM_TypeDef* tim) {
LCD_CTRL_BLINK_ON); LCD_CTRL_BLINK_ON);
wait_for_ready(); wait_for_ready();
write_byte(LCD_CLEAR); write_byte(LCD_CLEAR);
wait_for_ready();
return 0; return 0;
} }
void lcd_send_cmd(uint8_t cmd) {
// wait for the screen
wait_for_ready();
// select instruction register
io_write(GPIOA, LCD_MODE_CMD, PIN_10);
// send the command
write_byte(cmd);
}
void lcd_print(const char* txt) {
// prepare data
const char* c = txt;
// wait for the screen
wait_for_ready();
// select data register
io_write(GPIOA, LCD_MODE_DATA, PIN_10);
// send the caracters until end of string
while(*c != '\0') {
wait_for_ready();
write_byte(*c);
c++;
}
}
void lcd_set_cursor(uint8_t col, uint8_t row) {
lcd_send_cmd(LCD_DDRAM_ADDR | col);
}

View File

@ -5,6 +5,7 @@
#include "../config.h" #include "../config.h"
#include "timer.h" #include "timer.h"
#include "io.h" #include "io.h"
#include <stdlib.h>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/* LCD mode selection */ /* LCD mode selection */
@ -17,7 +18,7 @@ enum lcd_register {
/* LCD commands */ /* LCD commands */
enum lcd_command { enum lcd_command {
LCD_CLEAR = 0x01, LCD_CLEAR = 0x01,
LCD_CR = 0x02, LCD_CUR_HOME = 0x02,
LCD_ENTRY = 0x04, LCD_ENTRY = 0x04,
LCD_DISP_CTRL = 0x08, LCD_DISP_CTRL = 0x08,
LCD_SHIFT = 0x10, LCD_SHIFT = 0x10,
@ -67,11 +68,24 @@ enum lcd_func_option {
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int lcd_init(TIM_TypeDef* tim); /** lcd_init
* initialise the lcd, needed before anything else can be done
* the timer is used for delays and can't be in use when lcd functions are
* called
*/
int lcd_init(TIM_TypeDef* tim, uint8_t col, uint8_t row);
void lcd_write(uint8_t byte); /** lcd_send_cmd
* send the specified command to the lcd
*/
void lcd_send_cmd(uint8_t cmd);
uint8_t lcd_read(void); /** lcd_print
* print a null-terminated string on the lcd
*/
void lcd_print(const char* txt);
void lcd_set_cursor(uint8_t col, uint8_t row);
#endif #endif

View File

@ -1,9 +1,9 @@
#include "drivers/rcc.h" #include "drivers/rcc.h"
#include "drivers/io.h" #include "drivers/io.h"
#include "drivers/lcd.h"
#include "drivers/adc.h" #include "drivers/adc.h"
Clock_t sysclks; Clock_t sysclks;
#include "drivers/timer.h" #include "drivers/timer.h"
int val = 0; int val = 0;
@ -12,6 +12,8 @@ uint16_t data = 0;
static void timeout_cb(void) { static void timeout_cb(void) {
io_write(GPIOC, val, PIN_13); io_write(GPIOC, val, PIN_13);
val = !val; val = !val;
data = adc_read(ADC1, 2);
data -= adc_read(ADC1, 3);
} }
int main(void) { int main(void) {
@ -22,16 +24,31 @@ int main(void) {
return 0; return 0;
io_write(GPIOC, 1, PIN_13); io_write(GPIOC, 1, PIN_13);
timer_tick_init(TIM2, 1000, timeout_cb); if(io_configure(GPIOA, PIN_2 | PIN_3, IO_MODE_INPUT | IO_IN_ANALOG, 0))
timer_start(TIM2);
if(io_configure(GPIOA, PIN_4 | PIN_5, IO_MODE_INPUT | IO_IN_ANALOG, 0))
return 0; return 0;
if(adc_init(ADC1)) return 0; if(adc_init(ADC1)) return 0;
for(;;){ //int test = 0;
data = adc_read(ADC1, 5);
data -= adc_read(ADC1, 4); timer_tick_init(TIM2, 1000, timeout_cb);
timer_start(TIM2);
lcd_init(TIM1);
lcd_print(" et paf");
lcd_print("Hello world!");
lcd_send_cmd(LCD_CUR_HOME);
lcd_send_cmd(LCD_CUR_HOME);
lcd_set_cursor(5, 1);
while(1){
lcd_print("loop");
lcd_print("loop2");
lcd_print("loop3");
lcd_print("loop4");
//voltage = data*4.0f/4095.0f;
//temp = (voltage-0.45)/0.04f;
timer_wait_ms(TIM1, 200, 0);
} }
return 0; return 0;

View File

@ -6,8 +6,8 @@ STACK_SIZE = 0x400;
MEMORY MEMORY
{ {
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
RAM (rwx) : ORIGIN = 0x200000F0, LENGTH = 20K - (0xEC+0x4) RAM (rwx) : ORIGIN = 0x200000F0, LENGTH = 10K - (0xEC+0x4)
} }
/* Linker script to place sections and symbol values. Should be used together /* Linker script to place sections and symbol values. Should be used together