mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add_files
This commit is contained in:
parent
87ace89752
commit
bcb2f3aac1
292
package/BLIOT/LCD_driver.c
Normal file
292
package/BLIOT/LCD_driver.c
Normal file
@ -0,0 +1,292 @@
|
||||
#include "LCD_driver.h"
|
||||
#include <FreeRTOS.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <task.h>
|
||||
|
||||
volatile static pika_dev* LCD_DC = NULL;
|
||||
volatile static pika_dev* LCD_SPI = NULL;
|
||||
|
||||
static inline void _LCD_RS_SET(void) {
|
||||
uint32_t val = 1;
|
||||
pika_hal_write((pika_dev*)LCD_DC, &val, sizeof(val));
|
||||
}
|
||||
|
||||
static inline void _LCD_RS_CLR(void) {
|
||||
uint32_t val = 0;
|
||||
pika_hal_write((pika_dev*)LCD_DC, &val, sizeof(val));
|
||||
}
|
||||
|
||||
// 管理LCD重要参数
|
||||
// 默认为竖屏
|
||||
_lcd_dev lcddev;
|
||||
|
||||
// 画笔颜色,背景颜色
|
||||
u16 POINT_COLOR = 0x0000, BACK_COLOR = 0xFFFF;
|
||||
u16 DeviceCode;
|
||||
|
||||
#define LCD_WRITE_BATCH_SIZE 2048
|
||||
void LCD_write(uint8_t* data, uint32_t len) {
|
||||
for (int i = 0; i < len / LCD_WRITE_BATCH_SIZE; i++) {
|
||||
pika_hal_write((pika_dev*)LCD_SPI, data + i * LCD_WRITE_BATCH_SIZE,
|
||||
LCD_WRITE_BATCH_SIZE);
|
||||
}
|
||||
pika_hal_write((pika_dev*)LCD_SPI,
|
||||
data + len / LCD_WRITE_BATCH_SIZE * LCD_WRITE_BATCH_SIZE,
|
||||
len % LCD_WRITE_BATCH_SIZE);
|
||||
}
|
||||
|
||||
void LCD_WR_REG(u8 data) {
|
||||
LCD_RS_CLR();
|
||||
LCD_write(&data, 1);
|
||||
}
|
||||
|
||||
void LCD_WR_DATA(u8 data) {
|
||||
LCD_RS_SET();
|
||||
LCD_write(&data, 1);
|
||||
}
|
||||
|
||||
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue) {
|
||||
LCD_WR_REG(LCD_Reg);
|
||||
LCD_WR_DATA(LCD_RegValue);
|
||||
}
|
||||
|
||||
void LCD_WriteRAM_Prepare(void) {
|
||||
LCD_WR_REG(lcddev.wramcmd);
|
||||
}
|
||||
|
||||
static inline void color565_to_666(uint16_t color565, uint8_t* color666) {
|
||||
color666[0] = (color565 >> 8) & 0xF8;
|
||||
color666[1] = (color565 >> 3) & 0xFC;
|
||||
color666[2] = (color565 << 3);
|
||||
}
|
||||
|
||||
void LCD_writePoint(u16 color) {
|
||||
/* rgb 666 */
|
||||
uint8_t data[3] = {0};
|
||||
color565_to_666(color, data);
|
||||
LCD_RS_SET();
|
||||
LCD_write(data, 3);
|
||||
}
|
||||
|
||||
void LCD_drawPoint(u16 x, u16 y) {
|
||||
LCD_setCursor(x, y); // 设置光标位置
|
||||
LCD_writePoint(POINT_COLOR);
|
||||
}
|
||||
|
||||
void LCD_drawRegin(u16 x_start,
|
||||
u16 y_start,
|
||||
u16 x_end,
|
||||
u16 y_end,
|
||||
uint8_t* pData) {
|
||||
u32 size = (x_end - x_start) * (y_end - y_start) * 2;
|
||||
LCD_setRegion(x_start, y_start, x_end - 1, y_end - 1);
|
||||
LCD_RS_SET();
|
||||
LCD_write(pData, size);
|
||||
}
|
||||
|
||||
#define BUFF_LINE_NUM 4
|
||||
void LCD_fillRegin(u16 x_start, u16 y_start, u16 x_end, u16 y_end, u16 color) {
|
||||
size_t line_pix_size = x_end - x_start + 1;
|
||||
size_t buff_pix_size = (x_end - x_start + 1) * BUFF_LINE_NUM;
|
||||
uint8_t* buff = malloc(buff_pix_size * 3);
|
||||
if (NULL == buff) {
|
||||
printf("Error: malloc %d bytes failed\r\n", buff_pix_size * 3);
|
||||
}
|
||||
uint8_t color666[3] = {0};
|
||||
color565_to_666(color, color666);
|
||||
for (int i = 0; i < buff_pix_size; i++) {
|
||||
buff[i * 3] = color666[0];
|
||||
buff[i * 3 + 1] = color666[1];
|
||||
buff[i * 3 + 2] = color666[2];
|
||||
}
|
||||
LCD_setRegion(x_start, y_start, x_end, y_end);
|
||||
LCD_RS_SET();
|
||||
for (int i = 0; i < (y_end - y_start + 1) / BUFF_LINE_NUM; i++) {
|
||||
LCD_write(buff, buff_pix_size * 3);
|
||||
}
|
||||
if ((y_end - y_start + 1) % BUFF_LINE_NUM) {
|
||||
LCD_write(buff,
|
||||
line_pix_size * 3 * ((y_end - y_start + 1) % BUFF_LINE_NUM));
|
||||
}
|
||||
free(buff);
|
||||
}
|
||||
|
||||
void LCD_clear(u16 Color) {
|
||||
LCD_fillRegin(0, 0, lcddev.width - 1, lcddev.height - 1, Color);
|
||||
}
|
||||
|
||||
#define SPI_MODE_SOFT 1
|
||||
#define SPI_MODE_HARD 2
|
||||
|
||||
#define SPI_MODE SPI_MODE_HARD
|
||||
|
||||
void LCD_GPIOInit(void) {
|
||||
/* init spi */
|
||||
#if SPI_MODE == SPI_MODE_SOFT
|
||||
LCD_SPI = pika_hal_open(PIKA_HAL_SOFT_SPI, "SPI0");
|
||||
pika_hal_SOFT_SPI_config cfg_SPI = {0};
|
||||
cfg_SPI.CS = NULL;
|
||||
cfg_SPI.SCK = pika_hal_open(PIKA_HAL_GPIO, "P3");
|
||||
cfg_SPI.MISO = pika_hal_open(PIKA_HAL_GPIO, "P21");
|
||||
cfg_SPI.MOSI = pika_hal_open(PIKA_HAL_GPIO, "P20");
|
||||
#elif SPI_MODE == SPI_MODE_HARD
|
||||
LCD_SPI = pika_hal_open(PIKA_HAL_SPI, "SPI0");
|
||||
pika_hal_SPI_config cfg_SPI = {0};
|
||||
#endif
|
||||
cfg_SPI.master_or_slave = PIKA_HAL_SPI_MASTER;
|
||||
cfg_SPI.mode = PIKA_HAL_SPI_MODE_0;
|
||||
cfg_SPI.data_width = PIKA_HAL_SPI_DATA_WIDTH_8;
|
||||
cfg_SPI.speed = 40 * 1000 * 1000;
|
||||
pika_hal_ioctl((pika_dev*)LCD_SPI, PIKA_HAL_IOCTL_CONFIG, &cfg_SPI);
|
||||
pika_hal_ioctl((pika_dev*)LCD_SPI, PIKA_HAL_IOCTL_ENABLE);
|
||||
|
||||
/* init gpio */
|
||||
LCD_DC = pika_hal_open(PIKA_HAL_GPIO, "P0");
|
||||
pika_hal_GPIO_config cfg_DC = {0};
|
||||
cfg_DC.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
pika_hal_ioctl((pika_dev*)LCD_DC, PIKA_HAL_IOCTL_CONFIG, &cfg_DC);
|
||||
pika_hal_ioctl((pika_dev*)LCD_DC, PIKA_HAL_IOCTL_ENABLE);
|
||||
|
||||
pika_dev* LCD_CS = pika_hal_open(PIKA_HAL_GPIO, "P22");
|
||||
pika_hal_GPIO_config cfg_CS = {0};
|
||||
cfg_CS.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
pika_hal_ioctl((pika_dev*)LCD_CS, PIKA_HAL_IOCTL_CONFIG, &cfg_CS);
|
||||
pika_hal_ioctl((pika_dev*)LCD_CS, PIKA_HAL_IOCTL_ENABLE);
|
||||
uint32_t val = 0;
|
||||
pika_hal_write((pika_dev*)LCD_CS, &val, sizeof(val));
|
||||
}
|
||||
|
||||
void LCD_RESET(void) {}
|
||||
|
||||
void LCD_init(void) {
|
||||
LCD_GPIOInit(); // LCD GPIO初始化
|
||||
LCD_RESET(); // LCD 复位
|
||||
//************* ILI9488初始化**********//
|
||||
LCD_WR_REG(0XF7);
|
||||
LCD_WR_DATA(0xA9);
|
||||
LCD_WR_DATA(0x51);
|
||||
LCD_WR_DATA(0x2C);
|
||||
LCD_WR_DATA(0x82);
|
||||
LCD_WR_REG(0xC0);
|
||||
LCD_WR_DATA(0x11);
|
||||
LCD_WR_DATA(0x09);
|
||||
LCD_WR_REG(0xC1);
|
||||
LCD_WR_DATA(0x41);
|
||||
LCD_WR_REG(0XC5);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x0A);
|
||||
LCD_WR_DATA(0x80);
|
||||
LCD_WR_REG(0xB1);
|
||||
LCD_WR_DATA(0xB0);
|
||||
LCD_WR_DATA(0x11);
|
||||
LCD_WR_REG(0xB4);
|
||||
LCD_WR_DATA(0x02);
|
||||
LCD_WR_REG(0xB6);
|
||||
LCD_WR_DATA(0x02);
|
||||
LCD_WR_DATA(0x42);
|
||||
LCD_WR_REG(0xB7);
|
||||
LCD_WR_DATA(0xc6);
|
||||
LCD_WR_REG(0xBE);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x04);
|
||||
LCD_WR_REG(0xE9);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_REG(0x36);
|
||||
LCD_WR_DATA((1 << 3) | (0 << 7) | (1 << 6) | (1 << 5));
|
||||
LCD_WR_REG(0x3A);
|
||||
LCD_WR_DATA(0x66);
|
||||
LCD_WR_REG(0xE0);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x07);
|
||||
LCD_WR_DATA(0x10);
|
||||
LCD_WR_DATA(0x09);
|
||||
LCD_WR_DATA(0x17);
|
||||
LCD_WR_DATA(0x0B);
|
||||
LCD_WR_DATA(0x41);
|
||||
LCD_WR_DATA(0x89);
|
||||
LCD_WR_DATA(0x4B);
|
||||
LCD_WR_DATA(0x0A);
|
||||
LCD_WR_DATA(0x0C);
|
||||
LCD_WR_DATA(0x0E);
|
||||
LCD_WR_DATA(0x18);
|
||||
LCD_WR_DATA(0x1B);
|
||||
LCD_WR_DATA(0x0F);
|
||||
LCD_WR_REG(0XE1);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x17);
|
||||
LCD_WR_DATA(0x1A);
|
||||
LCD_WR_DATA(0x04);
|
||||
LCD_WR_DATA(0x0E);
|
||||
LCD_WR_DATA(0x06);
|
||||
LCD_WR_DATA(0x2F);
|
||||
LCD_WR_DATA(0x45);
|
||||
LCD_WR_DATA(0x43);
|
||||
LCD_WR_DATA(0x02);
|
||||
LCD_WR_DATA(0x0A);
|
||||
LCD_WR_DATA(0x09);
|
||||
LCD_WR_DATA(0x32);
|
||||
LCD_WR_DATA(0x36);
|
||||
LCD_WR_DATA(0x0F);
|
||||
LCD_WR_REG(0x11);
|
||||
vTaskDelay(120 / portTICK_RATE_MS);
|
||||
LCD_WR_REG(0x29);
|
||||
|
||||
LCD_direction(USE_HORIZONTAL); // 设置LCD显示方向
|
||||
// LCD_LED = 1; // 点亮背光
|
||||
LCD_clear(WHITE); // 清全屏白色
|
||||
}
|
||||
|
||||
void LCD_setRegion(u16 xStar, u16 yStar, u16 xEnd, u16 yEnd) {
|
||||
LCD_WR_REG(lcddev.setxcmd);
|
||||
LCD_WR_DATA(xStar >> 8);
|
||||
LCD_WR_DATA(0x00FF & xStar);
|
||||
LCD_WR_DATA(xEnd >> 8);
|
||||
LCD_WR_DATA(0x00FF & xEnd);
|
||||
|
||||
LCD_WR_REG(lcddev.setycmd);
|
||||
LCD_WR_DATA(yStar >> 8);
|
||||
LCD_WR_DATA(0x00FF & yStar);
|
||||
LCD_WR_DATA(yEnd >> 8);
|
||||
LCD_WR_DATA(0x00FF & yEnd);
|
||||
|
||||
LCD_WriteRAM_Prepare(); // 开始写入GRAM
|
||||
}
|
||||
|
||||
void LCD_setCursor(u16 Xpos, u16 Ypos) {
|
||||
LCD_setRegion(Xpos, Ypos, Xpos, Ypos);
|
||||
}
|
||||
|
||||
void LCD_direction(u8 direction) {
|
||||
lcddev.setxcmd = 0x2A;
|
||||
lcddev.setycmd = 0x2B;
|
||||
lcddev.wramcmd = 0x2C;
|
||||
switch (direction) {
|
||||
case 0:
|
||||
lcddev.width = LCD_W;
|
||||
lcddev.height = LCD_H;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (0 << 6) |
|
||||
(0 << 7)); // BGR==1,MY==0,MX==0,MV==0
|
||||
break;
|
||||
case 1:
|
||||
lcddev.width = LCD_H;
|
||||
lcddev.height = LCD_W;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (0 << 7) | (1 << 6) |
|
||||
(1 << 5)); // BGR==1,MY==1,MX==0,MV==1
|
||||
break;
|
||||
case 2:
|
||||
lcddev.width = LCD_W;
|
||||
lcddev.height = LCD_H;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (1 << 6) |
|
||||
(1 << 7)); // BGR==1,MY==0,MX==0,MV==0
|
||||
break;
|
||||
case 3:
|
||||
lcddev.width = LCD_H;
|
||||
lcddev.height = LCD_W;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (1 << 7) |
|
||||
(1 << 5)); // BGR==1,MY==1,MX==0,MV==1
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
103
package/BLIOT/LCD_driver.h
Normal file
103
package/BLIOT/LCD_driver.h
Normal file
@ -0,0 +1,103 @@
|
||||
#ifndef __LCD_H
|
||||
#define __LCD_H
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
#define u8 uint8_t
|
||||
#define u16 uint16_t
|
||||
#define u32 uint32_t
|
||||
|
||||
// LCD重要参数集
|
||||
typedef struct {
|
||||
u16 width; // LCD 宽度
|
||||
u16 height; // LCD 高度
|
||||
u16 id; // LCD ID
|
||||
u8 dir; // 横屏还是竖屏控制:0,竖屏;1,横屏。
|
||||
u16 wramcmd; // 开始写gram指令
|
||||
u16 setxcmd; // 设置x坐标指令
|
||||
u16 setycmd; // 设置y坐标指令
|
||||
} _lcd_dev;
|
||||
|
||||
// LCD参数
|
||||
extern _lcd_dev lcddev; // 管理LCD重要参数
|
||||
#define USE_HORIZONTAL \
|
||||
0 // 定义液晶屏顺时针旋转方向
|
||||
// 0-0度旋转,1-90度旋转,2-180度旋转,3-270度旋转
|
||||
|
||||
// 定义LCD的尺寸
|
||||
#define LCD_W 320
|
||||
#define LCD_H 480
|
||||
|
||||
// TFTLCD部分外要调用的函数
|
||||
extern u16 POINT_COLOR; // 默认红色
|
||||
extern u16 BACK_COLOR; // 背景颜色.默认为白色
|
||||
|
||||
//-----------------LCD端口定义----------------
|
||||
|
||||
// 如果使用官方库函数定义下列底层,速度将会下降到14帧每秒,建议采用我司推荐方法
|
||||
// 以下IO定义直接操作寄存器,快速IO操作,刷屏速率可以达到28帧每秒!
|
||||
|
||||
#define LCD_CS_SET _LCD_CS_SET
|
||||
#define LCD_RS_SET _LCD_RS_SET
|
||||
#define LCD_RST_SET _LCD_RST_SET
|
||||
|
||||
#define LCD_CS_CLR _LCD_CS_CLR
|
||||
#define LCD_RS_CLR _LCD_RS_CLR
|
||||
#define LCD_RST_CLR _LCD_RST_CLR
|
||||
|
||||
// 画笔颜色
|
||||
#define WHITE 0xFFFF
|
||||
#define BLACK 0x0000
|
||||
#define BLUE 0x001F
|
||||
#define BRED 0XF81F
|
||||
#define GRED 0XFFE0
|
||||
#define GBLUE 0X07FF
|
||||
#define RED 0xF800
|
||||
#define MAGENTA 0xF81F
|
||||
#define GREEN 0x07E0
|
||||
#define CYAN 0x7FFF
|
||||
#define YELLOW 0xFFE0
|
||||
#define BROWN 0XBC40 // 棕色
|
||||
#define BRRED 0XFC07 // 棕红色
|
||||
#define GRAY 0X8430 // 灰色
|
||||
// GUI颜色
|
||||
|
||||
#define DARKBLUE 0X01CF // 深蓝色
|
||||
#define LIGHTBLUE 0X7D7C // 浅蓝色
|
||||
#define GRAYBLUE 0X5458 // 灰蓝色
|
||||
// 以上三色为PANEL的颜色
|
||||
|
||||
#define LIGHTGREEN 0X841F // 浅绿色
|
||||
#define LIGHTGRAY 0XEF5B // 浅灰色(PANNEL)
|
||||
#define LGRAY 0XC618 // 浅灰色(PANNEL),窗体背景色
|
||||
|
||||
#define LGRAYBLUE 0XA651 // 浅灰蓝色(中间层颜色)
|
||||
#define LBBLUE 0X2B12 // 浅棕蓝色(选择条目的反色)
|
||||
|
||||
void LCD_init(void);
|
||||
void LCD_displayOn(void);
|
||||
void LCD_displayOff(void);
|
||||
void LCD_clear(u16 Color);
|
||||
void LCD_setCursor(u16 Xpos, u16 Ypos);
|
||||
void LCD_drawPoint(u16 x, u16 y); // 画点
|
||||
u16 LCD_readPoint(u16 x, u16 y); // 读点
|
||||
void LCD_drawLine(u16 x1, u16 y1, u16 x2, u16 y2);
|
||||
void LCD_drawRectangle(u16 x1, u16 y1, u16 x2, u16 y2);
|
||||
void LCD_setRegion(u16 xStar, u16 yStar, u16 xEnd, u16 yEnd);
|
||||
void LCD_writePoint(u16 Data);
|
||||
void LCD_drawRegin(u16 x_start,
|
||||
u16 y_start,
|
||||
u16 x_end,
|
||||
u16 y_end,
|
||||
uint8_t* pData);
|
||||
u16 LCD_RD_DATA(void); // 读取LCD数据
|
||||
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue);
|
||||
void LCD_WR_DATA(u8 data);
|
||||
u16 LCD_ReadReg(u8 LCD_Reg);
|
||||
void LCD_WriteRAM_Prepare(void);
|
||||
void LCD_WriteRAM(u16 RGB_Code);
|
||||
u16 LCD_ReadRAM(void);
|
||||
u16 LCD_BGR2RGB(u16 c);
|
||||
void LCD_SetParam(void);
|
||||
void LCD_direction(u8 direction);
|
||||
#endif
|
345
package/BLIOT/Touch_driver.c
Normal file
345
package/BLIOT/Touch_driver.c
Normal file
@ -0,0 +1,345 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "Touch_driver.h"
|
||||
#include <FreeRTOS.h>
|
||||
#include <string.h>
|
||||
#include <task.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static uint8_t GT911_Config[] = {
|
||||
0x81, 0x00, 0x04, 0x58, 0x02, 0x0A, 0x0C,
|
||||
0x20, 0x01, 0x08, 0x28, 0x05, 0x50, // 0x8047 - 0x8053
|
||||
0x3C, 0x0F, 0x05, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x8054 - 0x8060
|
||||
0x00, 0x89, 0x2A, 0x0B, 0x2D, 0x2B, 0x0F,
|
||||
0x0A, 0x00, 0x00, 0x01, 0xA9, 0x03, // 0x8061 - 0x806D
|
||||
0x2D, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x21, // 0x806E - 0x807A
|
||||
0x59, 0x94, 0xC5, 0x02, 0x07, 0x00, 0x00,
|
||||
0x04, 0x93, 0x24, 0x00, 0x7D, 0x2C, // 0x807B - 0x8087
|
||||
0x00, 0x6B, 0x36, 0x00, 0x5D, 0x42, 0x00,
|
||||
0x53, 0x50, 0x00, 0x53, 0x00, 0x00, // 0x8088 - 0x8094
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x8095 - 0x80A1
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80A2 - 0x80AD
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, // 0x80AE - 0x80BA
|
||||
0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0xFF,
|
||||
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, // 0x80BB - 0x80C7
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80C8 - 0x80D4
|
||||
0x02, 0x04, 0x06, 0x08, 0x0A, 0x0F, 0x10,
|
||||
0x12, 0x16, 0x18, 0x1C, 0x1D, 0x1E, // 0x80D5 - 0x80E1
|
||||
0x1F, 0x20, 0x21, 0x22, 0x24, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, // 0x80E2 - 0x80EE
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80EF - 0x80FB
|
||||
0x00, 0x00, 0xD6, 0x01}; // 0x80FC - 0x8100
|
||||
static GT911_Status_t CommunicationResult;
|
||||
static uint8_t TxBuffer[200];
|
||||
static uint8_t RxBuffer[200] = {0};
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void GT911_Reset(void);
|
||||
static void GT911_CalculateCheckSum(void);
|
||||
static GT911_Status_t GT911_SetCommandRegister(uint8_t command);
|
||||
static GT911_Status_t GT911_GetProductID(uint32_t* id);
|
||||
static GT911_Status_t GT911_SendConfig(void);
|
||||
static GT911_Status_t GT911_GetStatus(uint8_t* status);
|
||||
static GT911_Status_t GT911_SetStatus(uint8_t status);
|
||||
|
||||
GT911_Status_t GT911_I2C_Read_Mem(uint8_t Addr,
|
||||
uint16_t mem_addr,
|
||||
uint8_t* read_data,
|
||||
uint16_t read_length);
|
||||
|
||||
GT911_Status_t GT911_I2C_Write_Mem(uint8_t Addr,
|
||||
uint16_t mem_addr,
|
||||
uint8_t* write_data,
|
||||
uint16_t write_length);
|
||||
/* API Implementation
|
||||
* --------------------------------------------------------*/
|
||||
GT911_Status_t GT911_Init(GT911_Config_t config) {
|
||||
// Set X resolution
|
||||
GT911_Config[1] = config.X_Resolution & 0x00FF;
|
||||
GT911_Config[2] = (config.X_Resolution >> 8) & 0x00FF;
|
||||
// Set Y resolution
|
||||
GT911_Config[3] = config.Y_Resolution & 0x00FF;
|
||||
GT911_Config[4] = (config.Y_Resolution >> 8) & 0x00FF;
|
||||
// Set touch number
|
||||
GT911_Config[5] = config.Number_Of_Touch_Support;
|
||||
// set reverse Y
|
||||
GT911_Config[6] = 0;
|
||||
GT911_Config[6] |= config.ReverseY << 7;
|
||||
// set reverse X
|
||||
GT911_Config[6] |= config.ReverseX << 6;
|
||||
// set switch X2Y
|
||||
GT911_Config[6] |= config.SwithX2Y << 3;
|
||||
// set Sito
|
||||
GT911_Config[6] |= config.SoftwareNoiseReduction << 2;
|
||||
|
||||
// Reset chip
|
||||
GT911_Reset();
|
||||
// Get product ID
|
||||
uint32_t productID = 0;
|
||||
CommunicationResult = GT911_GetProductID(&productID);
|
||||
__platform_printf("GT911 ID:%d\r\n", productID);
|
||||
// Reset chip
|
||||
GT911_Reset();
|
||||
CommunicationResult = GT911_SendConfig();
|
||||
if (CommunicationResult != GT911_OK) {
|
||||
return CommunicationResult;
|
||||
}
|
||||
GT911_SetCommandRegister(0x00);
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_ReadTouch(TouchCordinate_t* cordinate,
|
||||
uint8_t* number_of_cordinate) {
|
||||
uint8_t StatusRegister;
|
||||
GT911_Status_t Result = GT911_NotResponse;
|
||||
Result = GT911_GetStatus(&StatusRegister);
|
||||
if (Result != GT911_OK) {
|
||||
return Result;
|
||||
}
|
||||
if ((StatusRegister & 0x80) != 0) {
|
||||
*number_of_cordinate = StatusRegister & 0x0F;
|
||||
if (*number_of_cordinate != 0) {
|
||||
for (uint8_t i = 0; i < *number_of_cordinate; i++) {
|
||||
TxBuffer[0] = ((GOODIX_POINT1_X_ADDR + (i * 8)) & 0xFF00) >> 8;
|
||||
TxBuffer[1] = (GOODIX_POINT1_X_ADDR + (i * 8)) & 0xFF;
|
||||
GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, 2);
|
||||
GT911_I2C_Read(GOODIX_ADDRESS, RxBuffer, 6);
|
||||
cordinate[i].x = RxBuffer[0];
|
||||
cordinate[i].x = (RxBuffer[1] << 8) + cordinate[i].x;
|
||||
cordinate[i].y = RxBuffer[2];
|
||||
cordinate[i].y = (RxBuffer[3] << 8) + cordinate[i].y;
|
||||
}
|
||||
}
|
||||
GT911_SetStatus(0);
|
||||
}
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
// Private functions Implementation
|
||||
// ---------------------------------------------------------*/
|
||||
static void GT911_Reset(void) {
|
||||
GT911_INT_Output();
|
||||
GT911_RST_Control(0);
|
||||
GT911_Delay(20);
|
||||
GT911_INT_Control(0);
|
||||
GT911_Delay(50);
|
||||
GT911_RST_Control(1);
|
||||
GT911_Delay(100);
|
||||
GT911_INT_Input();
|
||||
GT911_Delay(100);
|
||||
}
|
||||
|
||||
static void GT911_CalculateCheckSum(void) {
|
||||
GT911_Config[184] = 0;
|
||||
for (uint8_t i = 0; i < 184; i++) {
|
||||
GT911_Config[184] += GT911_Config[i];
|
||||
}
|
||||
GT911_Config[184] = (~GT911_Config[184]) + 1;
|
||||
}
|
||||
|
||||
static GT911_Status_t GT911_SetCommandRegister(uint8_t command) {
|
||||
TxBuffer[0] = (GOODIX_REG_COMMAND & 0xFF00) >> 8;
|
||||
TxBuffer[1] = GOODIX_REG_COMMAND & 0xFF;
|
||||
TxBuffer[2] = command;
|
||||
return GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, 3);
|
||||
}
|
||||
|
||||
static GT911_Status_t GT911_GetProductID(uint32_t* id) {
|
||||
TxBuffer[0] = (GOODIX_REG_ID & 0xFF00) >> 8;
|
||||
TxBuffer[1] = GOODIX_REG_ID & 0xFF;
|
||||
GT911_Status_t Result = GT911_NotResponse;
|
||||
Result = GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, 2);
|
||||
if (Result == GT911_OK) {
|
||||
Result = GT911_I2C_Read(GOODIX_ADDRESS, RxBuffer, 4);
|
||||
if (Result == GT911_OK) {
|
||||
memcpy(id, RxBuffer, 4);
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
static GT911_Status_t GT911_SendConfig(void) {
|
||||
GT911_CalculateCheckSum();
|
||||
TxBuffer[0] = (GOODIX_REG_CONFIG_DATA & 0xFF00) >> 8;
|
||||
TxBuffer[1] = GOODIX_REG_CONFIG_DATA & 0xFF;
|
||||
memcpy(&TxBuffer[2], GT911_Config, sizeof(GT911_Config));
|
||||
return GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, sizeof(GT911_Config) + 2);
|
||||
}
|
||||
|
||||
static GT911_Status_t GT911_GetStatus(uint8_t* status) {
|
||||
TxBuffer[0] = (GOODIX_READ_COORD_ADDR & 0xFF00) >> 8;
|
||||
TxBuffer[1] = GOODIX_READ_COORD_ADDR & 0xFF;
|
||||
GT911_Status_t Result = GT911_NotResponse;
|
||||
Result = GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, 2);
|
||||
if (Result == GT911_OK) {
|
||||
Result = GT911_I2C_Read(GOODIX_ADDRESS, RxBuffer, 1);
|
||||
if (Result == GT911_OK) {
|
||||
*status = RxBuffer[0];
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
static GT911_Status_t GT911_SetStatus(uint8_t status) {
|
||||
TxBuffer[0] = (GOODIX_READ_COORD_ADDR & 0xFF00) >> 8;
|
||||
TxBuffer[1] = GOODIX_READ_COORD_ADDR & 0xFF;
|
||||
TxBuffer[2] = status;
|
||||
return GT911_I2C_Write(GOODIX_ADDRESS, TxBuffer, 3);
|
||||
}
|
||||
|
||||
static pika_dev* TOUCH_INT = NULL;
|
||||
static pika_dev* TOUCH_RST = NULL;
|
||||
static pika_dev* TOUCH_IIC = NULL;
|
||||
|
||||
void GT911_INT_Input(void) {
|
||||
if (NULL == TOUCH_INT) {
|
||||
TOUCH_INT = pika_hal_open(PIKA_HAL_GPIO, "P17");
|
||||
}
|
||||
pika_hal_GPIO_config cfg = {0};
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_IN;
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_NONE;
|
||||
pika_hal_ioctl(TOUCH_INT, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(TOUCH_INT, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void GT911_INT_Output(void) {
|
||||
if (NULL == TOUCH_INT) {
|
||||
TOUCH_INT = pika_hal_open(PIKA_HAL_GPIO, "P17");
|
||||
}
|
||||
pika_hal_GPIO_config cfg = {0};
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
cfg.pull = PIKA_HAL_GPIO_PULL_NONE;
|
||||
pika_hal_ioctl(TOUCH_INT, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(TOUCH_INT, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
|
||||
void GT911_RST_Control(bool high_or_low) {
|
||||
if (NULL == TOUCH_RST) {
|
||||
TOUCH_RST = pika_hal_open(PIKA_HAL_GPIO, "P5");
|
||||
pika_hal_GPIO_config cfg = {0};
|
||||
cfg.dir = PIKA_HAL_GPIO_DIR_OUT;
|
||||
pika_hal_ioctl(TOUCH_RST, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(TOUCH_RST, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
uint32_t val = 0;
|
||||
switch (high_or_low) {
|
||||
case true:
|
||||
val = 1;
|
||||
pika_hal_write(TOUCH_RST, &val, sizeof(uint32_t));
|
||||
break;
|
||||
case false:
|
||||
val = 0;
|
||||
pika_hal_write(TOUCH_RST, &val, sizeof(uint32_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GT911_INT_Control(bool high_or_low) {
|
||||
if (NULL == TOUCH_INT) {
|
||||
GT911_INT_Output();
|
||||
}
|
||||
uint32_t val = 0;
|
||||
switch (high_or_low) {
|
||||
case true:
|
||||
val = 1;
|
||||
pika_hal_write(TOUCH_INT, &val, sizeof(uint32_t));
|
||||
break;
|
||||
case false:
|
||||
val = 0;
|
||||
pika_hal_write(TOUCH_INT, &val, sizeof(uint32_t));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GT911_Delay(uint16_t ms) {
|
||||
// HAL_Delay(ms);
|
||||
vTaskDelay(ms / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_I2C_Init(void) {
|
||||
if (NULL == TOUCH_IIC) {
|
||||
TOUCH_IIC = pika_hal_open(PIKA_HAL_IIC, "IIC3");
|
||||
pika_hal_IIC_config cfg = {0};
|
||||
cfg.slave_addr = GOODIX_ADDRESS;
|
||||
cfg.speed = 400000;
|
||||
cfg.timeout = 10000;
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_ENABLE);
|
||||
}
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_I2C_Write(uint8_t Addr,
|
||||
uint8_t* write_data,
|
||||
uint16_t write_length) {
|
||||
if (NULL == TOUCH_IIC) {
|
||||
GT911_I2C_Init();
|
||||
}
|
||||
pika_hal_IIC_config cfg = {0};
|
||||
cfg.slave_addr = Addr;
|
||||
cfg.mem_addr_ena = PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE;
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_write(TOUCH_IIC, write_data, write_length);
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_I2C_Write_Mem(uint8_t Addr,
|
||||
uint16_t mem_addr,
|
||||
uint8_t* write_data,
|
||||
uint16_t write_length) {
|
||||
if (NULL == TOUCH_IIC) {
|
||||
GT911_I2C_Init();
|
||||
}
|
||||
pika_hal_IIC_config cfg = {0};
|
||||
cfg.slave_addr = Addr;
|
||||
cfg.mem_addr = mem_addr;
|
||||
cfg.mem_addr_ena = PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE;
|
||||
cfg.mem_addr_size = sizeof(uint16_t);
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_write(TOUCH_IIC, write_data, write_length);
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_I2C_Read(uint8_t Addr,
|
||||
uint8_t* read_data,
|
||||
uint16_t read_length) {
|
||||
if (NULL == TOUCH_IIC) {
|
||||
GT911_I2C_Init();
|
||||
}
|
||||
pika_hal_IIC_config cfg = {0};
|
||||
cfg.slave_addr = Addr;
|
||||
cfg.mem_addr_ena = PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE;
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_read(TOUCH_IIC, read_data, read_length);
|
||||
return GT911_OK;
|
||||
}
|
||||
|
||||
GT911_Status_t GT911_I2C_Read_Mem(uint8_t Addr,
|
||||
uint16_t mem_addr,
|
||||
uint8_t* read_data,
|
||||
uint16_t read_length) {
|
||||
if (NULL == TOUCH_IIC) {
|
||||
GT911_I2C_Init();
|
||||
}
|
||||
pika_hal_IIC_config cfg = {0};
|
||||
cfg.slave_addr = Addr;
|
||||
cfg.mem_addr = mem_addr;
|
||||
cfg.mem_addr_ena = PIKA_HAL_IIC_MEM_ADDR_ENA_ENABLE;
|
||||
cfg.mem_addr_size = sizeof(uint16_t);
|
||||
pika_hal_ioctl(TOUCH_IIC, PIKA_HAL_IOCTL_CONFIG, &cfg);
|
||||
pika_hal_read(TOUCH_IIC, read_data, read_length);
|
||||
return GT911_OK;
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF
|
||||
* FILE****/
|
122
package/BLIOT/Touch_driver.h
Normal file
122
package/BLIOT/Touch_driver.h
Normal file
@ -0,0 +1,122 @@
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __GT911_H_
|
||||
#define __GT911_H_
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
// GOODIX REGISTER ADDRESSES
|
||||
//
|
||||
#define GOODIX_ADDRESS 0x5D
|
||||
|
||||
// Write only registers
|
||||
#define GOODIX_REG_COMMAND 0x8040
|
||||
#define GOODIX_REG_ESD_CHECK 0x8041
|
||||
#define GOODIX_REG_PROXIMITY_EN 0x8042
|
||||
|
||||
// Read/write registers
|
||||
// The version number of the configuration file
|
||||
#define GOODIX_REG_CONFIG_DATA 0x8047
|
||||
// X output maximum value (LSB 2 bytes)
|
||||
#define GOODIX_REG_MAX_X 0x8048
|
||||
// Y output maximum value (LSB 2 bytes)
|
||||
#define GOODIX_REG_MAX_Y 0x804A
|
||||
// Maximum number of output contacts: 1~5 (4 bit value 3:0, 7:4 is reserved)
|
||||
#define GOODIX_REG_MAX_TOUCH 0x804C
|
||||
|
||||
// Module switch 1
|
||||
// 7:6 Reserved, 5:4 Stretch rank, 3 X2Y, 2 SITO (Single sided ITO touch
|
||||
// screen), 1:0 INT Trigger mode */
|
||||
#define GOODIX_REG_MOD_SW1 0x804D
|
||||
// Module switch 2
|
||||
// 7:1 Reserved, 0 Touch key */
|
||||
#define GOODIX_REG_MOD_SW2 0x804E
|
||||
|
||||
// Number of debuffs fingers press/release
|
||||
#define GOODIX_REG_SHAKE_CNT 0x804F
|
||||
|
||||
// X threshold
|
||||
#define GOODIX_REG_X_THRESHOLD 0x8057
|
||||
|
||||
// Configuration update fresh
|
||||
#define GOODIX_REG_CONFIG_FRESH 0x8100
|
||||
|
||||
// ReadOnly registers (device and coordinates info)
|
||||
// Product ID (LSB 4 bytes, GT9110: 0x06 0x00 0x00 0x09)
|
||||
#define GOODIX_REG_ID 0x8140
|
||||
// Firmware version (LSB 2 bytes)
|
||||
#define GOODIX_REG_FW_VER 0x8144
|
||||
|
||||
// Current output X resolution (LSB 2 bytes)
|
||||
#define GOODIX_READ_X_RES 0x8146
|
||||
// Current output Y resolution (LSB 2 bytes)
|
||||
#define GOODIX_READ_Y_RES 0x8148
|
||||
// Module vendor ID
|
||||
#define GOODIX_READ_VENDOR_ID 0x814A
|
||||
|
||||
#define GOODIX_READ_COORD_ADDR 0x814E
|
||||
|
||||
#define GOODIX_POINT1_X_ADDR 0x8150
|
||||
#define GOODIX_POINT1_Y_ADDR 0x8152
|
||||
|
||||
/* Commands for REG_COMMAND */
|
||||
// 0: read coordinate state
|
||||
#define GOODIX_CMD_READ 0x00
|
||||
// 1: difference value original value
|
||||
#define GOODIX_CMD_DIFFVAL 0x01
|
||||
// 2: software reset
|
||||
#define GOODIX_CMD_SOFTRESET 0x02
|
||||
// 3: Baseline update
|
||||
#define GOODIX_CMD_BASEUPDATE 0x03
|
||||
// 4: Benchmark calibration
|
||||
#define GOODIX_CMD_CALIBRATE 0x04
|
||||
// 5: Off screen (send other invalid)
|
||||
#define GOODIX_CMD_SCREEN_OFF 0x05
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
GT911_OK = 0,
|
||||
GT911_Error = 1,
|
||||
GT911_NotResponse = 2
|
||||
} GT911_Status_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t X_Resolution;
|
||||
uint16_t Y_Resolution;
|
||||
uint8_t Number_Of_Touch_Support;
|
||||
bool ReverseX;
|
||||
bool ReverseY;
|
||||
bool SwithX2Y;
|
||||
bool SoftwareNoiseReduction;
|
||||
|
||||
} GT911_Config_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
} TouchCordinate_t;
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
GT911_Status_t GT911_Init(GT911_Config_t config);
|
||||
GT911_Status_t GT911_ReadTouch(TouchCordinate_t* cordinate,
|
||||
uint8_t* number_of_cordinate);
|
||||
|
||||
// User method implementation prototype
|
||||
// ----------------------------------------*/
|
||||
void GT911_INT_Input(void);
|
||||
void GT911_INT_Output(void);
|
||||
void GT911_RST_Control(bool high_or_low);
|
||||
void GT911_INT_Control(bool high_or_low);
|
||||
void GT911_Delay(uint16_t ms);
|
||||
GT911_Status_t GT911_I2C_Init(void);
|
||||
GT911_Status_t GT911_I2C_Write(uint8_t Addr,
|
||||
uint8_t* write_data,
|
||||
uint16_t write_length);
|
||||
GT911_Status_t GT911_I2C_Read(uint8_t Addr,
|
||||
uint8_t* read_data,
|
||||
uint16_t read_length);
|
||||
|
||||
#endif /* __GT911_H_ */
|
@ -23,6 +23,10 @@ int pika_hal_platform_GPIO_read(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_gpio_input_get(platform_gpio, &value);
|
||||
uint32_t value_in = value;
|
||||
memcpy(buf, &value_in, sizeof(value_in));
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("GPIO read port %d to %d\r\n", platform_gpio->port,
|
||||
value_in);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -136,34 +136,34 @@ int pika_hal_platform_IIC_ioctl_disable(pika_dev* dev) {
|
||||
int pika_hal_platform_IIC_write(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
pika_hal_IIC_config* cfg = (pika_hal_IIC_config*)dev->ioctl_config;
|
||||
if (!cfg->mem_addr_ena) {
|
||||
return hosal_i2c_master_send(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
if (cfg->mem_addr_ena == PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE) {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Write %d bytes to 0x%02x\r\n", count,
|
||||
cfg->slave_addr);
|
||||
#endif
|
||||
return hosal_i2c_master_send(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
} else {
|
||||
return hosal_i2c_mem_write(platform_i2c, cfg->slave_addr, cfg->mem_addr,
|
||||
cfg->mem_addr_size, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Write %d bytes to 0x%02x, mem_addr:0x%02x\r\n",
|
||||
count, cfg->slave_addr, cfg->mem_addr);
|
||||
#endif
|
||||
return hosal_i2c_mem_write(platform_i2c, cfg->slave_addr, cfg->mem_addr,
|
||||
cfg->mem_addr_size, buf, count,
|
||||
cfg->timeout);
|
||||
}
|
||||
}
|
||||
|
||||
int pika_hal_platform_IIC_read(pika_dev* dev, void* buf, size_t count) {
|
||||
hosal_i2c_dev_t* platform_i2c = (hosal_i2c_dev_t*)dev->platform_data;
|
||||
pika_hal_IIC_config* cfg = (pika_hal_IIC_config*)dev->ioctl_config;
|
||||
if (!cfg->mem_addr_ena) {
|
||||
return hosal_i2c_master_recv(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
#ifdef PIKA_DEBUG_ENABLE
|
||||
if (cfg->mem_addr_ena == PIKA_HAL_IIC_MEM_ADDR_ENA_DISABLE) {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Read %d bytes from 0x%02x\r\n", count,
|
||||
cfg->slave_addr);
|
||||
#endif
|
||||
return hosal_i2c_master_recv(platform_i2c, cfg->slave_addr, buf, count,
|
||||
cfg->timeout);
|
||||
} else {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("IIC: Read %d bytes from 0x%02x, mem_addr:0x%02x\r\n",
|
||||
|
@ -1,22 +1,23 @@
|
||||
#include <hosal_dma.h>
|
||||
#include <hosal_spi.h>
|
||||
#include "../PikaStdDevice/pika_hal.h"
|
||||
|
||||
static int _num2pin(int num, uint8_t* mosi, uint8_t* miso, uint8_t* scli) {
|
||||
static int _num2pin(int num, uint8_t* mosi, uint8_t* miso, uint8_t* clk) {
|
||||
/*********************** BL602 **************************
|
||||
* SPI0 -----> MOSI:P20, MISO:P0, SCLK:P22
|
||||
* SPI0 -----> MOSI:P20, MISO:P21, SCLK:P3
|
||||
*/
|
||||
switch (num) {
|
||||
case 0:
|
||||
*mosi = 20;
|
||||
*miso = 0;
|
||||
*scli = 22;
|
||||
*miso = 21;
|
||||
*clk = 3;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("SPI%d: mosi:%d, miso:%d, scli:%d\r\n", num, *mosi, *miso,
|
||||
*scli);
|
||||
*clk);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -32,6 +33,12 @@ int pika_hal_platform_SPI_open(pika_dev* dev, char* name) {
|
||||
if (0 == _num2pin(spi_num, &platform_spi->config.pin_mosi,
|
||||
&platform_spi->config.pin_miso,
|
||||
&platform_spi->config.pin_clk)) {
|
||||
#if PIKA_DEBUG_ENABLE
|
||||
__platform_printf("SPI: mosi:%d, miso:%d, scli:%d\r\n",
|
||||
platform_spi->config.pin_mosi,
|
||||
platform_spi->config.pin_miso,
|
||||
platform_spi->config.pin_clk);
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
__platform_printf("SPI: Open SPI%d failed\r\n", spi_num);
|
||||
@ -54,7 +61,8 @@ int pika_hal_platform_SPI_ioctl_config(pika_dev* dev,
|
||||
hosal_spi_dev_t* platform_spi = (hosal_spi_dev_t*)dev->platform_data;
|
||||
if (!dev->is_enabled) {
|
||||
platform_spi->port = 0;
|
||||
platform_spi->config.dma_enable = 0;
|
||||
platform_spi->config.dma_enable = 1;
|
||||
hosal_dma_init();
|
||||
platform_spi->config.freq = cfg->speed;
|
||||
platform_spi->p_arg = NULL;
|
||||
switch (cfg->master_or_slave) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user