调试记录2
使用硬件SPI
上次的模拟SPI速度有些感人,这次使用硬件SPI
csi_gpio_pin_t pin_clk;
csi_gpio_pin_t pin_mosi;
csi_gpio_pin_t pin_cs;
csi_gpio_pin_t pin_miso;
static void oled_pinmux_init()
{
csi_pin_set_mux(PA28, PA28_SPI1_SCK); //clk
csi_pin_set_mux(PA29, PA29_SPI1_MOSI); //mosi
csi_pin_set_mux(PA27, PIN_FUNC_GPIO); //cs
csi_pin_set_mux(PA30, PIN_FUNC_GPIO); //miso
}
static void oled_gpio_init()
{
csi_gpio_pin_init(&pin_cs, PA27);
csi_gpio_pin_dir(&pin_cs, GPIO_DIRECTION_OUTPUT);
csi_gpio_pin_init(&pin_miso, PA30); //dc
csi_gpio_pin_dir(&pin_miso, GPIO_DIRECTION_OUTPUT);
int32_t ret = csi_spi_init(&spi_handle, 1);
if (ret < 0) {
printf("csi spi init failed\r\n");
return NULL;
}
csi_spi_mode(&spi_handle, SPI_MASTER);
ret = csi_spi_baud(&spi_handle, 20000000);
csi_spi_cp_format(&spi_handle, SPI_FORMAT_CPOL0_CPHA0);
csi_spi_frame_len(&spi_handle, SPI_FRAME_LEN_8);
csi_spi_select_slave(&spi_handle, 1);
#ifdef SPI_USE_DMA
csi_spi_attach_callback(&spi_handle, spi_event_cb, NULL);
csi_spi_link_dma(&spi_handle, NULL, &spi_recv_dma);
#endif
}
移植uGUI
μGUI - free Open Source GUI module for embedded systems | Embedded Lightning
µGUI is a free and open source graphic library for embedded systems. It is platform-independent and can be easily ported to almost any microcontroller system. As long as the display is capable of showing graphics, µGUI is not restricted to a certain display technology. Therefore, display technologies such as LCD, TFT, E-Paper, LED or OLED are supported. The whole module consists of two files: ugui.c and ugui.h.
采用 里的文件
需要提供以下驱动,主要是画点函数
UG_GUI gui;
static UG_RESULT HW_FillFrame ( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c)
{
LCD_Fill(x1,y1,x2,y2,c);
return UG_RESULT_OK;
}
static UG_RESULT HW_DrawLine ( UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, UG_COLOR c)
{
return UG_RESULT_OK;
}
static void pset(UG_S16 x,UG_S16 y,UG_COLOR c)
{
LCD_DrawPoint(x,y,c);
}
void gui_ugui_init()
{
oled_hard_init();
UG_Init(&gui, pset, 160 , 80 ) ;
// UG_DriverRegister( DRIVER_DRAW_LINE, HW_DrawLine ) ;
UG_DriverRegister( DRIVER_FILL_FRAME, HW_FillFrame ) ;
// UG_DriverEnable ( DRIVER_DRAW_LINE ) ;
UG_DriverEnable ( DRIVER_FILL_FRAME ) ;
}
这样就可以直接调用其丰富的绘图函数了
|