add lcd show nrf24 data
This commit is contained in:
@@ -396,6 +396,16 @@ void LCD_Clear(uint16_t Color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LCD_ClearRect(uint16_t Color, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
|
||||||
|
{
|
||||||
|
LCD_Address_Set(x, y, width, height);
|
||||||
|
for(uint16_t i=0; i<max_width; i++) {
|
||||||
|
for (uint16_t j=0; j<max_height; j++) {
|
||||||
|
LCD_WR_DATA(Color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LCD_ShowChinese(uint16_t x, uint16_t y, uint8_t index, uint16_t color)
|
void LCD_ShowChinese(uint16_t x, uint16_t y, uint8_t index, uint16_t color)
|
||||||
{
|
{
|
||||||
const uint8_t *p = (uint8_t*) &(Hzk[index*2][0]);
|
const uint8_t *p = (uint8_t*) &(Hzk[index*2][0]);
|
||||||
|
@@ -61,6 +61,7 @@ void LCD_Address_Set(uint16_t x1, uint16_t y1, uint16_t x2,uint16_t y2);
|
|||||||
void LCD_SetDisplayMode(lcd_display_mode_t m);
|
void LCD_SetDisplayMode(lcd_display_mode_t m);
|
||||||
|
|
||||||
void LCD_Clear(uint16_t Color);
|
void LCD_Clear(uint16_t Color);
|
||||||
|
void LCD_ClearRect(uint16_t Color, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
|
||||||
void LCD_ShowChinese(uint16_t x,uint16_t y,uint8_t index,uint16_t color);
|
void LCD_ShowChinese(uint16_t x,uint16_t y,uint8_t index,uint16_t color);
|
||||||
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
|
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
|
||||||
void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color);
|
void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color);
|
||||||
|
@@ -1,38 +1,6 @@
|
|||||||
#include "mcu_init.h"
|
#include "mcu_init.h"
|
||||||
#include "tos_k.h"
|
#include "tos_k.h"
|
||||||
#include "lcd.h"
|
|
||||||
|
|
||||||
#define LCD_TASK_SIZE 1024
|
|
||||||
k_task_t lcd_handle;
|
|
||||||
uint8_t lcd_stk[LCD_TASK_SIZE];
|
|
||||||
|
|
||||||
|
|
||||||
void task_lcd(void *arg)
|
|
||||||
{
|
|
||||||
uint16_t color_table[] = { WHITE, BLUE, RED, GREEN, CYAN, YELLOW, GRAY};
|
|
||||||
|
|
||||||
for(int i=0; ; i++) {
|
|
||||||
LCD_SetDisplayMode((i % 2) ? LCD_DISPMODE_HORIZONTAL_MIRROR : LCD_DISPMODE_HORIZONTAL);
|
|
||||||
LCD_Clear(BLACK);
|
|
||||||
|
|
||||||
uint16_t color = color_table[i % (sizeof(color_table)/sizeof(uint16_t))];
|
|
||||||
|
|
||||||
|
|
||||||
LCD_ShowChinese(50, 16, 0, color);
|
|
||||||
LCD_ShowChinese(50+16+28, 16, 1, color);
|
|
||||||
|
|
||||||
for(int j=0; j<6; j++) {
|
|
||||||
LCD_ShowChinese(22+j*20, 48, j+2, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
tos_task_delay(1000);
|
|
||||||
LCD_Clear(BLACK);
|
|
||||||
|
|
||||||
LCD_ShowString(24, 32, "TencentOS tiny", color);
|
|
||||||
|
|
||||||
tos_task_delay(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void nrf24l01_init();
|
void nrf24l01_init();
|
||||||
|
|
||||||
@@ -45,8 +13,6 @@ void main(void) {
|
|||||||
|
|
||||||
nrf24l01_init();
|
nrf24l01_init();
|
||||||
|
|
||||||
tos_task_create(&lcd_handle, "lcd", task_lcd, NULL, 7, lcd_stk, LCD_TASK_SIZE, 0);
|
|
||||||
|
|
||||||
tos_knl_start();
|
tos_knl_start();
|
||||||
|
|
||||||
die:
|
die:
|
||||||
|
@@ -4,11 +4,13 @@
|
|||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "gd32vf103_gpio.h"
|
#include "gd32vf103_gpio.h"
|
||||||
#include "nrf24l01_gd32v_hal.h"
|
#include "nrf24l01_gd32v_hal.h"
|
||||||
|
#include "lcd.h"
|
||||||
|
|
||||||
#define USE_SPI1
|
#define USE_SPI1
|
||||||
|
|
||||||
extern k_sem_t sem_led;
|
|
||||||
k_sem_t sem_nrf;
|
k_sem_t sem_nrf;
|
||||||
|
k_sem_t sem_led;
|
||||||
|
k_mutex_t mutex_lcd;
|
||||||
|
|
||||||
#define TASK_SIZE (8*1024)
|
#define TASK_SIZE (8*1024)
|
||||||
k_task_t task_nrf24_handle;
|
k_task_t task_nrf24_handle;
|
||||||
@@ -19,6 +21,11 @@ k_task_t led_handle;
|
|||||||
uint8_t led_stk[LED_TASK_SIZE];
|
uint8_t led_stk[LED_TASK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
#define LCD_TASK_SIZE 1024
|
||||||
|
k_task_t lcd_handle;
|
||||||
|
uint8_t lcd_stk[LCD_TASK_SIZE];
|
||||||
|
|
||||||
|
|
||||||
#define CE_GPIO_PORT GPIOA
|
#define CE_GPIO_PORT GPIOA
|
||||||
#define CE_PIN GPIO_PIN_3
|
#define CE_PIN GPIO_PIN_3
|
||||||
#define CSN_GPIO_PORT GPIOB
|
#define CSN_GPIO_PORT GPIOB
|
||||||
@@ -28,30 +35,13 @@ uint8_t led_stk[LED_TASK_SIZE];
|
|||||||
|
|
||||||
void task_nrf24();
|
void task_nrf24();
|
||||||
|
|
||||||
|
char lcd_buf[64];
|
||||||
|
|
||||||
k_sem_t sem_led;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int port;
|
|
||||||
int pin;
|
|
||||||
} Led_t;
|
|
||||||
|
|
||||||
Led_t leds[] = {
|
|
||||||
{ LEDR_GPIO_PORT, LEDR_PIN },
|
|
||||||
{ LEDG_GPIO_PORT, LEDG_PIN },
|
|
||||||
{ LEDB_GPIO_PORT, LEDB_PIN }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void task_led(void *arg)
|
void task_led(void *arg)
|
||||||
{
|
{
|
||||||
int task_cnt1 = 0;
|
int task_cnt1 = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
//printf("hello world from %s cnt: %d\n", __func__, task_cnt1++);
|
|
||||||
|
|
||||||
tos_sem_pend(&sem_led, ~0);
|
tos_sem_pend(&sem_led, ~0);
|
||||||
|
|
||||||
gpio_bit_reset(LEDB_GPIO_PORT, LEDB_PIN);
|
gpio_bit_reset(LEDB_GPIO_PORT, LEDB_PIN);
|
||||||
tos_task_delay(50);
|
tos_task_delay(50);
|
||||||
gpio_bit_set(LEDB_GPIO_PORT, LEDB_PIN);
|
gpio_bit_set(LEDB_GPIO_PORT, LEDB_PIN);
|
||||||
@@ -59,6 +49,24 @@ void task_led(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void task_lcd(void *arg)
|
||||||
|
{
|
||||||
|
strcpy(lcd_buf, "initializing...");
|
||||||
|
LCD_SetDisplayMode(LCD_DISPMODE_HORIZONTAL_MIRROR);
|
||||||
|
LCD_Clear(BLACK);
|
||||||
|
const uint16_t x = 0;
|
||||||
|
const uint16_t y = 32;
|
||||||
|
uint8_t oldlen = strlen(lcd_buf);
|
||||||
|
for(int i=0; ; i++) {
|
||||||
|
tos_mutex_pend(&mutex_lcd);
|
||||||
|
uint8_t newlen = strlen(lcd_buf);
|
||||||
|
if(newlen < oldlen) {
|
||||||
|
LCD_Clear(BLACK);
|
||||||
|
}
|
||||||
|
oldlen = newlen;
|
||||||
|
LCD_ShowString(x, y, lcd_buf, CYAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void nrf24l01_init() {
|
void nrf24l01_init() {
|
||||||
rcu_periph_clock_enable(RCU_GPIOA);
|
rcu_periph_clock_enable(RCU_GPIOA);
|
||||||
@@ -128,8 +136,10 @@ void nrf24l01_init() {
|
|||||||
|
|
||||||
tos_sem_create(&sem_nrf, 1);
|
tos_sem_create(&sem_nrf, 1);
|
||||||
tos_sem_create(&sem_led, 1);
|
tos_sem_create(&sem_led, 1);
|
||||||
|
tos_mutex_create(&mutex_lcd);
|
||||||
tos_task_create(&task_nrf24_handle, "task_nrf24", task_nrf24, NULL, 5, task_nrf24_stk, TASK_SIZE, 0);
|
tos_task_create(&task_nrf24_handle, "task_nrf24", task_nrf24, NULL, 5, task_nrf24_stk, TASK_SIZE, 0);
|
||||||
tos_task_create(&led_handle, "led", task_led, NULL, 6, led_stk, LED_TASK_SIZE, 0);
|
tos_task_create(&led_handle, "led", task_led, NULL, 6, led_stk, LED_TASK_SIZE, 0);
|
||||||
|
tos_task_create(&lcd_handle, "lcd", task_lcd, NULL, 7, lcd_stk, LCD_TASK_SIZE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXTI5_9_IRQHandler(void)
|
void EXTI5_9_IRQHandler(void)
|
||||||
@@ -216,6 +226,8 @@ void test_nrf24l01_irq_rx()
|
|||||||
|
|
||||||
tos_sem_post(&sem_led);
|
tos_sem_post(&sem_led);
|
||||||
|
|
||||||
|
strncpy(lcd_buf, buf, len);
|
||||||
|
tos_mutex_post(&mutex_lcd);
|
||||||
printf("received %u bytes from pipe %u: ", len, pipe);
|
printf("received %u bytes from pipe %u: ", len, pipe);
|
||||||
|
|
||||||
for(int i=0; i<len; i++) {
|
for(int i=0; i<len; i++) {
|
||||||
@@ -252,7 +264,8 @@ void test_nrf24l01_rx() {
|
|||||||
nrf_poll_read_payload(buf, &len, &pipe);
|
nrf_poll_read_payload(buf, &len, &pipe);
|
||||||
|
|
||||||
tos_sem_post(&sem_led);
|
tos_sem_post(&sem_led);
|
||||||
|
strncpy(lcd_buf, buf, len);
|
||||||
|
tos_mutex_post(&mutex_lcd);
|
||||||
printf("received %u bytes from pipe %u: ", len, pipe);
|
printf("received %u bytes from pipe %u: ", len, pipe);
|
||||||
|
|
||||||
for(int i=0; i<len; i++) {
|
for(int i=0; i<len; i++) {
|
||||||
|
Reference in New Issue
Block a user