Prechádzať zdrojové kódy

modified: Character display is assigned to Core 1.

Satoshi Yoneda 2 mesiacov pred
rodič
commit
3f5ae6510d
3 zmenil súbory, kde vykonal 73 pridanie a 14 odobranie
  1. 54 8
      display.c
  2. 16 3
      display.h
  3. 3 3
      usb_keypad1.c

+ 54 - 8
display.c

@@ -5,12 +5,15 @@
 #include "hardware/i2c.h"
 #include "pico/util/queue.h"
 #include "pico/multicore.h"
-
-// #include "font8x8.h"
+#include "pico/util/queue.h"
 
 uint8_t display_buffer[OLED_BUF_LEN];
 
-void display_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse)
+// ディスプレイコマンドqueue
+queue_t command_queue;
+
+
+void _d_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse)
 {
     uint32_t offset = col_x * FONT_WIDTH + OLED_WIDTH * col_y + FONT_WIDTH;
 
@@ -31,19 +34,41 @@ void display_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse)
     }
 }
 
-void display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse)
+void _d_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse)
 {
     int i = 0;
     while(str[i] != '\0') {
-        display_putchar(str[i++], col_x++, col_y, reverse);
+        _d_putchar(str[i++], col_x++, col_y, reverse);
     }
 }
 
-void display_clear(void)
+void _d_clear(void)
 {
     fill(display_buffer, 0x00);
 }
 
+bool display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse)
+{
+    display_cmd_t       cmd;
+
+    cmd.command = DISPLAY_CMD_PUTSTR;
+    cmd.x1 = col_x;
+    cmd.y1 = col_y;
+    cmd.x2 = (uint8_t)reverse;
+    strcpy((char *)cmd.data, str);
+    
+    return queue_try_add(&command_queue, &cmd);
+}
+
+bool display_clear(void)
+{
+    display_cmd_t cmd;
+
+    cmd.command = DISPLAY_CMD_CLEAR;
+
+    return queue_try_add(&command_queue, &cmd);
+}
+
 void display_main(void)
 {
     // I2C初期化
@@ -65,14 +90,35 @@ void display_main(void)
     calc_render_area_buflen(&frame_area);
     // ディスプレイクリア
     fill(display_buffer, 0x00);
+
+    // ディスプレイメインループ
     while(true) {
+        display_cmd_t cmd;
+
         render(display_buffer, &frame_area);
-        sleep_us(6*1000);
+        while(! queue_is_empty(&command_queue)) {
+            queue_remove_blocking(&command_queue, &cmd);
+            switch(cmd.command) {
+             case DISPLAY_CMD_CLEAR:
+                _d_clear();
+                break;
+                
+             case DISPLAY_CMD_PUTSTR:
+                _d_putstr((char *)cmd.data, cmd.x1, cmd.y1, (bool)cmd.x2);
+                break;
+                
+             default:
+                break;
+            };
+        }
+        sleep_us(4*1000);
     }
 }
 
 void display_init(void)
 {
-    multicore_reset_core1();
+    //queue初期化
+    queue_init(&command_queue, sizeof(display_cmd_t), 8);
+    // display_main起動
     multicore_launch_core1(display_main);
 }

+ 16 - 3
display.h

@@ -9,8 +9,21 @@
 
 void display_init(void);
 void display_main(void);
-void display_clear(void);
-void display_putchar(char c, uint8_t col_x, uint8_t col_y, bool reverse);
-void display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse);
+bool display_clear(void);
+bool display_putstr(char *str, uint8_t col_x, uint8_t col_y, bool reverse);
+
+
+typedef struct {
+    uint16_t    command;
+    uint8_t     x1,y1;
+    uint8_t     x2,y2;
+    uint8_t     data[OLED_WIDTH/FONT_WIDTH + 1];
+} display_cmd_t;
+
+
+#define DISPLAY_CMD_NONE    0x0000
+#define DISPLAY_CMD_CLEAR   0x0001
+#define DISPLAY_CMD_PUTSTR  0x0002
+
 
 #endif

+ 3 - 3
usb_keypad1.c

@@ -13,9 +13,9 @@
 #define KEYBOARD_REPORT_COUNT    6
 uint8_t key_report[KEYBOARD_REPORT_COUNT] = {0,0,0,0,0,0};
 
-char report_str[OLED_WIDTH/FONT_WIDTH];        // キーボードレポート表示用
-char indicator_str[OLED_WIDTH/FONT_WIDTH];     // LEDインジケーター表示用
-char debug_str[OLED_WIDTH/FONT_WIDTH];
+char report_str[OLED_WIDTH/FONT_WIDTH + 1];        // キーボードレポート表示用
+char indicator_str[OLED_WIDTH/FONT_WIDTH + 1];     // LEDインジケーター表示用
+char debug_str[OLED_WIDTH/FONT_WIDTH + 1];
 
 // レポート配列をクリア
 inline void clear_key_report(void)