初始化就不写上来了,很长.....
以下为修改的panel_nt35510_draw_bitmap函数,使颜色高低字节交换:
- static esp_err_t panel_nt35510_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end,
- const void *color_data)
- {
- nt35510_panel_t *nt35510 = __containerof(panel, nt35510_panel_t, base);
- assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position");
- esp_lcd_panel_io_handle_t io = nt35510->io;
- x_start += nt35510->x_gap;
- x_end += nt35510->x_gap;
- y_start += nt35510->y_gap;
- y_end += nt35510->y_gap;
- // define an area of frame memory where MCU can access
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 0, (uint16_t[]) {
- (x_start >> 8) & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 1, (uint16_t[]) {
- x_start & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 2, (uint16_t[]) {
- ((x_end - 1) >> 8) & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 3, (uint16_t[]) {
- (x_end - 1) & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 0, (uint16_t[]) {
- (y_start >> 8) & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 1, (uint16_t[]) {
- y_start & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 2, (uint16_t[]) {
- ((y_end - 1) >> 8) & 0xFF,
- }, 2), TAG, "io tx param failed");
- ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 3, (uint16_t[]) {
- (y_end - 1) & 0xFF,
- }, 2), TAG, "io tx param failed");
- // transfer frame buffer
- size_t len = (x_end - x_start) * (y_end - y_start) * nt35510->fb_bits_per_pixel / 8;
- //****************start***************************************************************************************
- // 为交换后的数据创建一个新缓冲区
- uint16_t *swapped_color_data = malloc(len);
- if (!swapped_color_data) {
- return ESP_ERR_NO_MEM;
- }
- // 对颜色数据进行高低字节交换
- const uint16_t *src = (const uint16_t *)color_data;
- for (size_t i = 0; i < len / 2; i++) { // len / 2 因为 len 是以字节为单位,而我们处理的是 16 位数据
- swapped_color_data[i] = (src[i] >> 8) | (src[i] << 8);
- }
- // 发送交换后的颜色数据
- esp_err_t err = esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR << 8, swapped_color_data, len);
- if (err != ESP_OK) {
- free(swapped_color_data);
- return err;
- }
- free(swapped_color_data);
- //*****************end**************************************************************************************
- return ESP_OK;
- }