Skip to content

Commit 34ab8dd

Browse files
committed
stmhal: Update and improve LCD driver.
Still some method names to iron out, and funtionality to add, but this will do for the first, basic version.
1 parent 0294661 commit 34ab8dd

File tree

8 files changed

+384
-335
lines changed

8 files changed

+384
-335
lines changed

stmhal/lcd.c

Lines changed: 360 additions & 306 deletions
Large diffs are not rendered by default.

stmhal/lcd.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
void lcd_init(void);
28-
void lcd_print_str(const char *str);
29-
void lcd_print_strn(const char *str, unsigned int len);
27+
extern const mp_obj_type_t pyb_lcd_type;

stmhal/main.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
#include "storage.h"
5959
#include "sdcard.h"
6060
#include "ff.h"
61-
#include "lcd.h"
6261
#include "rng.h"
6362
#include "accel.h"
6463
#include "servo.h"
@@ -95,10 +94,6 @@ void __fatal_error(const char *msg) {
9594
led_state(4, 1);
9695
stdout_tx_strn("\nFATAL ERROR:\n", 14);
9796
stdout_tx_strn(msg, strlen(msg));
98-
#if 0 && MICROPY_HW_HAS_LCD
99-
lcd_print_strn("\nFATAL ERROR:\n", 14);
100-
lcd_print_strn(msg, strlen(msg));
101-
#endif
10297
for (uint i = 0;;) {
10398
led_toggle(((i++) & 3) + 1);
10499
for (volatile uint delay = 0; delay < 10000000; delay++) {
@@ -333,11 +328,6 @@ int main(void) {
333328
pin_init();
334329
extint_init();
335330

336-
#if MICROPY_HW_HAS_LCD
337-
// LCD init (just creates class, init hardware by calling LCD())
338-
lcd_init();
339-
#endif
340-
341331
// local filesystem init
342332
{
343333
// try to mount the flash

stmhal/modpyb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "accel.h"
5555
#include "servo.h"
5656
#include "dac.h"
57+
#include "lcd.h"
5758
#include "usb.h"
5859
#include "ff.h"
5960
#include "portmodules.h"
@@ -390,6 +391,10 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
390391
#if MICROPY_HW_HAS_MMA7660
391392
{ MP_OBJ_NEW_QSTR(MP_QSTR_Accel), (mp_obj_t)&pyb_accel_type },
392393
#endif
394+
395+
#if MICROPY_HW_HAS_LCD
396+
{ MP_OBJ_NEW_QSTR(MP_QSTR_LCD), (mp_obj_t)&pyb_lcd_type },
397+
#endif
393398
};
394399

395400
STATIC const mp_obj_dict_t pyb_module_globals = {

stmhal/printf.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,13 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
196196
}
197197

198198
void stdout_print_strn(void *data, const char *str, unsigned int len) {
199-
// send stdout to UART, USB CDC VCP, and LCD if nothing else
200-
bool any = false;
201-
199+
// TODO this needs to be replaced with a proper stdio interface ala CPython
200+
// send stdout to UART and USB CDC VCP
202201
if (pyb_uart_global_debug != PYB_UART_NONE) {
203202
uart_tx_strn_cooked(pyb_uart_global_debug, str, len);
204-
any = true;
205203
}
206204
if (usb_vcp_is_enabled()) {
207205
usb_vcp_send_strn_cooked(str, len);
208-
any = true;
209-
}
210-
if (!any) {
211-
#if 0
212-
#if MICROPY_HW_HAS_LCD
213-
lcd_print_strn(str, len);
214-
#endif
215-
#endif
216206
}
217207
}
218208

stmhal/pybstdio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@
3838
#include "usb.h"
3939
#include "uart.h"
4040

41+
// TODO make stdin, stdout and stderr writable objects so they can
42+
// be changed by Python code.
43+
4144
void stdout_tx_str(const char *str) {
4245
if (pyb_uart_global_debug != PYB_UART_NONE) {
4346
uart_tx_str(pyb_uart_global_debug, str);
4447
}
45-
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
48+
#if 0 && defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
4649
lcd_print_str(str);
4750
#endif
4851
usb_vcp_send_str(str);
@@ -52,7 +55,7 @@ void stdout_tx_strn(const char *str, uint len) {
5255
if (pyb_uart_global_debug != PYB_UART_NONE) {
5356
uart_tx_strn(pyb_uart_global_debug, str, len);
5457
}
55-
#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
58+
#if 0 && defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
5659
lcd_print_strn(str, len);
5760
#endif
5861
usb_vcp_send_strn(str, len);

stmhal/qstrdefsport.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ Q(have_cdc)
5757
Q(hid)
5858
Q(time)
5959
Q(rng)
60-
Q(LCD)
6160
Q(SD)
6261
Q(SDcard)
6362
Q(FileIO)
@@ -247,6 +246,17 @@ Q(sleep)
247246
// for input
248247
Q(input)
249248

249+
// for LCD class
250+
Q(LCD)
251+
Q(command)
252+
Q(contrast)
253+
Q(light)
254+
Q(fill)
255+
Q(get)
256+
Q(pixel)
257+
Q(text)
258+
Q(show)
259+
250260
// for stm module
251261
Q(stm)
252262
Q(mem)

stmhal/usb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ void USR_KEYBRD_ProcessData(uint8_t pbuf) {
199199
led_state(4, 1);
200200
USB_OTG_BSP_mDelay(50);
201201
led_state(4, 0);
202-
//lcd_print_strn((char*)&pbuf, 1);
203202
usb_keyboard_key = pbuf;
204203
}
205204

0 commit comments

Comments
 (0)