LCD模块触摸液晶屏
WARNING
📌 如有侵权,请联系我们删除!!
模块来源
采购链接:
https://detail.tmall.com/item.htm?abbucket=1&id=609295381138&ns=1&spm=a21n57.1.0.0.38d8523cN9L761
资料下载链接:
- 百度网盘链接: https://pan.baidu.com/s/15cBaOlTF644s2NLUcs4Oiw
- 提取码:764s
规格参数
- LCD尺寸:2.8寸
- 显示区域:57.6mm * 47.2mm
- 驱动IC:ILI9341/ST7789
- 分辨率:320*240(RGB)
- 色彩深度:16bit(65K色)
- 工作电压:3.3V
- 背光电压:3.3V(默认)/5V
- 接口方式:16位,8080/6800并口
- 模块尺寸:51mm * 82.6mm
移植过程
我们的目标是将例程移植至天空星GD32F407上。按照以下步骤,即可完成移植。
- 将源码导入工程;
- 根据编译报错处进行粗改;
- 修改引脚配置;
- 修改时序配置;
- 移植验证。
查看资料
我们从网盘中下载资料然后得到下方的文件夹:
然后按照下面的路径找到相关压缩文件
移植至工程
我们将压缩文件解压出来,我们需要移动1个文件夹和两个文件:ATK_MD0280文件夹、demo.c和demo.h
然后我们打开工程将刚才加入的文件添加一下。
引脚选择
LCD屏幕接口 | 天空星开发板引脚 |
---|---|
CS | PA1 |
RS | PA0 |
WR | PA3 |
RD | PA4 |
RST | PA5 |
D0 | PA6 |
D1 | PA7 |
D2 | PC4 |
D3 | PC5 |
D4 | PB0 |
D5 | PB1 |
D6 | PE7 |
D7 | PE8 |
D8 | PE9 |
D9 | PE10 |
D10 | PE11 |
D11 | PE12 |
D12 | PE13 |
D13 | PE14 |
D14 | PE15 |
D15 | PB11 |
BL | PB10 |
MI | PB12 |
PEN | PB13 |
TCS | PB14 |
MO | PD8 |
CLK | PD10 |
我们将各个文件中的代码修改成以下代码框中的样子。
atk_md0280.h
c
/**
****************************************************************************************************
* @file atk_md0280.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#ifndef __ATK_MD0280_H
#define __ATK_MD0280_H
#include "board.h"
/* 定义ATK-MD0280模块LCD尺寸 */
#define ATK_MD0280_LCD_WIDTH 240
#define ATK_MD0280_LCD_HEIGHT 320
/* 定义是否使用ATK-MD0280模块触摸 */
#define ATK_MD0280_USING_TOUCH 1
/* 定义ATK-MD0280模块启用的字体 */
#define ATK_MD0280_FONT_12 1
#define ATK_MD0280_FONT_16 1
#define ATK_MD0280_FONT_24 1
#define ATK_MD0280_FONT_32 1
/* 默认启用触摸 */
#ifndef ATK_MD0280_USING_TOUCH
#define ATK_MD0280_USING_TOUCH 1
#endif
/* 默认启用12号字体 */
#if ((ATK_MD0280_FONT_12 == 0) && (ATK_MD0280_FONT_16 == 0) && (ATK_MD0280_FONT_24 == 0) && (ATK_MD0280_FONT_32 == 0))
#undef ATK_MD0280_FONT_12
#defien ATK_MD0280_FONT_12 1
#endif
/* 包含头文件 */
#if (ATK_MD0280_USING_TOUCH != 0)
#include "atk_md0280_touch.h"
#endif
/* 引脚定义 */
#define ATK_MD0280_BL_GPIO_RCU RCU_GPIOB
#define ATK_MD0280_BL_GPIO_PORT GPIOB
#define ATK_MD0280_BL_GPIO_PIN GPIO_PIN_10
/* IO操作 */
#define ATK_MD0280_BL(x) gpio_bit_write(ATK_MD0280_BL_GPIO_PORT, ATK_MD0280_BL_GPIO_PIN, x)
/* ATK-MD0280模块LCD扫描方向枚举 */
typedef enum
{
ATK_MD0280_LCD_SCAN_DIR_L2R_U2D = 0x0008, /* 从左到右,从上到下 */
ATK_MD0280_LCD_SCAN_DIR_L2R_D2U = 0x0088, /* 从左到右,从下到上 */
ATK_MD0280_LCD_SCAN_DIR_R2L_U2D = 0x0048, /* 从右到左,从上到下 */
ATK_MD0280_LCD_SCAN_DIR_R2L_D2U = 0x00C8, /* 从右到左,从下到上 */
ATK_MD0280_LCD_SCAN_DIR_U2D_L2R = 0x0028, /* 从上到下,从左到右 */
ATK_MD0280_LCD_SCAN_DIR_U2D_R2L = 0x0068, /* 从上到下,从右到左 */
ATK_MD0280_LCD_SCAN_DIR_D2U_L2R = 0x00A8, /* 从下到上,从左到右 */
ATK_MD0280_LCD_SCAN_DIR_D2U_R2L = 0x00E8, /* 从下到上,从右到左 */
} atk_md0280_lcd_scan_dir_t;
/* ATK-MD0280模块LCD旋转方向枚举 */
typedef enum
{
ATK_MD0280_LCD_DISP_DIR_0 = 0x00, /* LCD顺时针旋转0°显示内容 */
ATK_MD0280_LCD_DISP_DIR_90, /* LCD顺时针旋转90°显示内容 */
ATK_MD0280_LCD_DISP_DIR_180, /* LCD顺时针旋转180°显示内容 */
ATK_MD0280_LCD_DISP_DIR_270, /* LCD顺时针旋转270°显示内容 */
} atk_md0280_lcd_disp_dir_t;
/* ATK-MD0280模块LCD显示字体枚举 */
typedef enum
{
#if (ATK_MD0280_FONT_12 != 0)
ATK_MD0280_LCD_FONT_12, /* 12号字体 */
#endif
#if (ATK_MD0280_FONT_16 != 0)
ATK_MD0280_LCD_FONT_16, /* 16号字体 */
#endif
#if (ATK_MD0280_FONT_24 != 0)
ATK_MD0280_LCD_FONT_24, /* 24号字体 */
#endif
#if (ATK_MD0280_FONT_32 != 0)
ATK_MD0280_LCD_FONT_32, /* 32号字体 */
#endif
} atk_md0280_lcd_font_t;
/* ATK-MD0280模块LCD显示数字模式枚举 */
typedef enum
{
ATK_MD0280_NUM_SHOW_NOZERO = 0x00, /* 数字高位0不显示 */
ATK_MD0280_NUM_SHOW_ZERO, /* 数字高位0显示 */
} atk_md0280_num_mode_t;
/* 常用颜色定义(RGB565) */
#define ATK_MD0280_WHITE 0xFFFF
#define ATK_MD0280_BLACK 0x0000
#define ATK_MD0280_BLUE 0x001F
#define ATK_MD0280_BRED 0XF81F
#define ATK_MD0280_GRED 0XFFE0
#define ATK_MD0280_GBLUE 0X07FF
#define ATK_MD0280_RED 0xF800
#define ATK_MD0280_MAGENTA 0xF81F
#define ATK_MD0280_GREEN 0x07E0
#define ATK_MD0280_CYAN 0x7FFF
#define ATK_MD0280_YELLOW 0xFFE0
#define ATK_MD0280_BROWN 0XBC40
#define ATK_MD0280_BRRED 0XFC07
#define ATK_MD0280_GRAY 0X8430
/* 错误代码 */
#define ATK_MD0280_EOK 0 /* 没有错误 */
#define ATK_MD0280_ERROR 1 /* 错误 */
#define ATK_MD0280_EINVAL 2 /* 非法参数 */
/* 操作函数 */
uint8_t atk_md0280_init(void); /* ATK-MD0280模块初始化 */
uint16_t atk_md0280_get_lcd_width(void); /* 获取ATK-MD0280模块LCD宽度 */
uint16_t atk_md0280_get_lcd_height(void); /* 获取ATK-MD0280模块LCD高度 */
void atk_md0280_backlight_on(void); /* 开启ATK-MD0280模块LCD背光 */
void atk_md0280_backlight_off(void); /* 关闭ATK-MD0280模块LCD背光 */
void atk_md0280_display_on(void); /* 开启ATK-MD0280模块LCD显示 */
void atk_md0280_display_off(void); /* 关闭ATK-MD0280模块LCD显示 */
uint8_t atk_md0280_set_scan_dir(atk_md0280_lcd_scan_dir_t scan_dir); /* 设置ATK-MD0280模块LCD扫描方向 */
uint8_t atk_md0280_set_disp_dir(atk_md0280_lcd_disp_dir_t disp_dir); /* 设置ATK-MD0280模块LCD显示方向 */
atk_md0280_lcd_scan_dir_t atk_md0280_get_scan_dir(void); /* 获取ATK-MD0280模块LCD扫描方向 */
atk_md0280_lcd_disp_dir_t atk_md0280_get_disp_dir(void); /* 获取ATK-MD0280模块LCD显示方向 */
void atk_md0280_fill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color); /* ATK-MD0280模块LCD区域填充 */
void atk_md0280_clear(uint16_t color); /* ATK-MD0280模块LCD清屏 */
void atk_md0280_draw_point(uint16_t x, uint16_t y, uint16_t color); /* ATK-MD0280模块LCD画点 */
uint16_t atk_md0280_read_point(uint16_t x, uint16_t y); /* ATK-MD0280模块LCD读点 */
void atk_md0280_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); /* ATK-MD0280模块LCD画线段 */
void atk_md0280_draw_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); /* ATK-MD0280模块LCD画矩形框 */
void atk_md0280_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color); /* ATK-MD0280模块LCD画圆形框 */
void atk_md0280_show_char(uint16_t x, uint16_t y, char ch, atk_md0280_lcd_font_t font, uint16_t color); /* ATK-MD0280模块LCD显示1个字符 */
void atk_md0280_show_string(uint16_t x, uint16_t y, uint16_t width, uint16_t height, char *str, atk_md0280_lcd_font_t font, uint16_t color); /* ATK-MD0280模块LCD显示字符串 */
void atk_md0280_show_xnum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, atk_md0280_num_mode_t mode, atk_md0280_lcd_font_t font, uint16_t color); /* ATK-MD0280模块LCD显示数字,可控制显示高位0 */
void atk_md0280_show_num(uint16_t x, uint16_t y, uint32_t num, uint8_t len, atk_md0280_lcd_font_t font, uint16_t color); /* ATK-MD0280模块LCD显示数字,不显示高位0 */
void atk_md0280_show_pic(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *pic); /* ATK-MD0280模块LCD图片 */
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
atk_md0280.c
c
/**
****************************************************************************************************
* @file atk_md0280.c
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#include "atk_md0280.h"
#include "atk_md0280_font.h"
#include "atk_md0280_gpio.h"
/* ATK-MD0280模块LCD驱动器ID */
#define ATK_MD0280_CHIP_ID1 0x9341
#define ATK_MD0280_CHIP_ID2 0x8552
/* ATK-MD0280模块LCD扫描方向 */
#define ATK_MD0280_SCAN_DIR_L2R_U2D (0x0000)
#define ATK_MD0280_SCAN_DIR_L2R_D2U (0x0080)
#define ATK_MD0280_SCAN_DIR_R2L_U2D (0x0040)
#define ATK_MD0280_SCAN_DIR_R2L_D2U (0x00C0)
#define ATK_MD0280_SCAN_DIR_U2D_L2R (0x0020)
#define ATK_MD0280_SCAN_DIR_U2D_R2L (0x0060)
#define ATK_MD0280_SCAN_DIR_D2U_L2R (0x00A0)
#define ATK_MD0280_SCAN_DIR_D2U_R2L (0x00E0)
/* ATK-MD0280模块状态数据结构体 */
static struct
{
uint16_t chip_id; /* 驱动器ID */
uint16_t width; /* LCD宽度 */
uint16_t height; /* LCD高度 */
atk_md0280_lcd_scan_dir_t scan_dir; /* LCD扫描方向 */
atk_md0280_lcd_disp_dir_t disp_dir; /* LCD显示方向 */
} g_atk_md0280_sta = {0};
/**
* @brief ATK-MD0280模块硬件初始化
* @param 无
* @retval 无
*/
static void atk_md0280_hw_init(void)
{
/* 使能时钟 */
rcu_periph_clock_enable(ATK_MD0280_BL_GPIO_RCU);
/* 初始化RS引脚 */
gpio_mode_set(ATK_MD0280_BL_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_BL_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_BL_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_BL_GPIO_PIN);
ATK_MD0280_BL(0);
}
/**
* @brief 获取ATK-MD0280模块驱动器ID
* @param 无
* @retval 无
*/
static inline uint16_t atk_md0280_get_chip_id(void)
{
uint16_t chip_id;
/* 尝试获取ID1 */
atk_md0280_gpio_write_cmd(0xD3);
chip_id = atk_md0280_gpio_read_dat();
chip_id = atk_md0280_gpio_read_dat();
chip_id = atk_md0280_gpio_read_dat() << 8;
chip_id |= (atk_md0280_gpio_read_dat()) & 0x00FF;
if (chip_id != ATK_MD0280_CHIP_ID1)
{
/* 尝试获取ID2 */
atk_md0280_gpio_write_cmd(0x04);
chip_id = atk_md0280_gpio_read_dat();
chip_id = atk_md0280_gpio_read_dat();
chip_id = atk_md0280_gpio_read_dat() << 8;
chip_id |= (atk_md0280_gpio_read_dat()) & 0x00FF;
}
return chip_id;
}
/**
* @brief ATK-MD0280模块寄存器初始化
* @param 无
* @retval 无
*/
static void atk_md0280_reg_init(void)
{
if (g_atk_md0280_sta.chip_id == ATK_MD0280_CHIP_ID1)
{
atk_md0280_gpio_write_cmd(0xCF);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0xC1);
atk_md0280_gpio_write_dat(0x30);
atk_md0280_gpio_write_cmd(0xED);
atk_md0280_gpio_write_dat(0x64);
atk_md0280_gpio_write_dat(0x03);
atk_md0280_gpio_write_dat(0x12);
atk_md0280_gpio_write_dat(0x81);
atk_md0280_gpio_write_cmd(0xE8);
atk_md0280_gpio_write_dat(0x85);
atk_md0280_gpio_write_dat(0x10);
atk_md0280_gpio_write_dat(0x7A);
atk_md0280_gpio_write_cmd(0xCB);
atk_md0280_gpio_write_dat(0x39);
atk_md0280_gpio_write_dat(0x2C);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x34);
atk_md0280_gpio_write_dat(0x02);
atk_md0280_gpio_write_cmd(0xF7);
atk_md0280_gpio_write_dat(0x20);
atk_md0280_gpio_write_cmd(0xEA);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_cmd(0xC0);
atk_md0280_gpio_write_dat(0x1B);
atk_md0280_gpio_write_cmd(0xC1);
atk_md0280_gpio_write_dat(0x01);
atk_md0280_gpio_write_cmd(0xC5);
atk_md0280_gpio_write_dat(0x30);
atk_md0280_gpio_write_dat(0x30);
atk_md0280_gpio_write_cmd(0xC7);
atk_md0280_gpio_write_dat(0xB7);
atk_md0280_gpio_write_cmd(0x36);
atk_md0280_gpio_write_dat(0x48);
atk_md0280_gpio_write_cmd(0x3A);
atk_md0280_gpio_write_dat(0x55);
atk_md0280_gpio_write_cmd(0xB1);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x1A);
atk_md0280_gpio_write_cmd(0xB6);
atk_md0280_gpio_write_dat(0x0A);
atk_md0280_gpio_write_dat(0xA2);
atk_md0280_gpio_write_cmd(0xF2);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_cmd(0x26);
atk_md0280_gpio_write_dat(0x01);
atk_md0280_gpio_write_cmd(0xE0);
atk_md0280_gpio_write_dat(0x0F);
atk_md0280_gpio_write_dat(0x2A);
atk_md0280_gpio_write_dat(0x28);
atk_md0280_gpio_write_dat(0x08);
atk_md0280_gpio_write_dat(0x0E);
atk_md0280_gpio_write_dat(0x08);
atk_md0280_gpio_write_dat(0x54);
atk_md0280_gpio_write_dat(0xA9);
atk_md0280_gpio_write_dat(0x43);
atk_md0280_gpio_write_dat(0x0A);
atk_md0280_gpio_write_dat(0x0F);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_cmd(0xE1);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x15);
atk_md0280_gpio_write_dat(0x17);
atk_md0280_gpio_write_dat(0x07);
atk_md0280_gpio_write_dat(0x11);
atk_md0280_gpio_write_dat(0x06);
atk_md0280_gpio_write_dat(0x2B);
atk_md0280_gpio_write_dat(0x56);
atk_md0280_gpio_write_dat(0x3C);
atk_md0280_gpio_write_dat(0x05);
atk_md0280_gpio_write_dat(0x10);
atk_md0280_gpio_write_dat(0x0F);
atk_md0280_gpio_write_dat(0x3F);
atk_md0280_gpio_write_dat(0x3F);
atk_md0280_gpio_write_dat(0x0F);
atk_md0280_gpio_write_cmd(0x2B);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x01);
atk_md0280_gpio_write_dat(0x3F);
atk_md0280_gpio_write_cmd(0x2A);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0xEF);
atk_md0280_gpio_write_cmd(0x11);
delay_ms(100);
atk_md0280_gpio_write_cmd(0x29);
}
else if (g_atk_md0280_sta.chip_id == ATK_MD0280_CHIP_ID2)
{
atk_md0280_gpio_write_cmd(0x11);
delay_ms(120);
atk_md0280_gpio_write_cmd(0x36);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_cmd(0x3A);
atk_md0280_gpio_write_dat(0x05);
atk_md0280_gpio_write_cmd(0xB2);
atk_md0280_gpio_write_dat(0x0C);
atk_md0280_gpio_write_dat(0x0C);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x33);
atk_md0280_gpio_write_dat(0x33);
atk_md0280_gpio_write_cmd(0xB7);
atk_md0280_gpio_write_dat(0x35);
atk_md0280_gpio_write_cmd(0xBB);
atk_md0280_gpio_write_dat(0x32);
atk_md0280_gpio_write_cmd(0xC0);
atk_md0280_gpio_write_dat(0x0C);
atk_md0280_gpio_write_cmd(0xC2);
atk_md0280_gpio_write_dat(0x01);
atk_md0280_gpio_write_cmd(0xC3);
atk_md0280_gpio_write_dat(0x10);
atk_md0280_gpio_write_cmd(0xC4);
atk_md0280_gpio_write_dat(0x20);
atk_md0280_gpio_write_cmd(0xC6);
atk_md0280_gpio_write_dat(0x0F);
atk_md0280_gpio_write_cmd(0xD0);
atk_md0280_gpio_write_dat(0xA4);
atk_md0280_gpio_write_dat(0xA1);
atk_md0280_gpio_write_cmd(0xE0);
atk_md0280_gpio_write_dat(0xD0);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x02);
atk_md0280_gpio_write_dat(0x07);
atk_md0280_gpio_write_dat(0x0A);
atk_md0280_gpio_write_dat(0x28);
atk_md0280_gpio_write_dat(0x32);
atk_md0280_gpio_write_dat(0x44);
atk_md0280_gpio_write_dat(0x42);
atk_md0280_gpio_write_dat(0x06);
atk_md0280_gpio_write_dat(0x0E);
atk_md0280_gpio_write_dat(0x12);
atk_md0280_gpio_write_dat(0x14);
atk_md0280_gpio_write_dat(0x17);
atk_md0280_gpio_write_cmd(0xE1);
atk_md0280_gpio_write_dat(0xD0);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x02);
atk_md0280_gpio_write_dat(0x07);
atk_md0280_gpio_write_dat(0x0A);
atk_md0280_gpio_write_dat(0x28);
atk_md0280_gpio_write_dat(0x31);
atk_md0280_gpio_write_dat(0x54);
atk_md0280_gpio_write_dat(0x47);
atk_md0280_gpio_write_dat(0x0E);
atk_md0280_gpio_write_dat(0x1C);
atk_md0280_gpio_write_dat(0x17);
atk_md0280_gpio_write_dat(0x1B);
atk_md0280_gpio_write_dat(0x1E);
atk_md0280_gpio_write_cmd(0x2A);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0xEF);
atk_md0280_gpio_write_cmd(0x2B);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x00);
atk_md0280_gpio_write_dat(0x01);
atk_md0280_gpio_write_dat(0x3F);
atk_md0280_gpio_write_cmd(0x29);
}
}
/**
* @brief 设置ATK-MD0280模块列地址
* @param 无
* @retval 无
*/
static void atk_md0280_set_column_address(uint16_t sc, uint16_t ec)
{
atk_md0280_gpio_write_cmd(0x2A);
atk_md0280_gpio_write_dat((uint8_t)(sc >> 8) & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)sc & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)(ec >> 8) & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)ec & 0xFF);
}
/**
* @brief 设置ATK-MD0280模块页地址
* @param 无
* @retval 无
*/
static void atk_md0280_set_page_address(uint16_t sp, uint16_t ep)
{
atk_md0280_gpio_write_cmd(0x2B);
atk_md0280_gpio_write_dat((uint8_t)(sp >> 8) & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)sp & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)(ep >> 8) & 0xFF);
atk_md0280_gpio_write_dat((uint8_t)ep & 0xFF);
}
/**
* @brief 开始写ATK-MD0280模块显存
* @param 无
* @retval 无
*/
static void atk_md0280_start_write_memory(void)
{
atk_md0280_gpio_write_cmd(0x2C);
}
/**
* @brief 开始读ATK-MD0280模块显存
* @param 无
* @retval 无
*/
static void atk_md0280_start_read_memory(void)
{
atk_md0280_gpio_write_cmd(0x2E);
}
/**
* @brief 平方函数,x^y
* @param x: 底数
* y: 指数
* @retval x^y
*/
static uint32_t atk_md0280_pow(uint8_t x, uint8_t y)
{
uint8_t loop;
uint32_t res = 1;
for (loop=0; loop<y; loop++)
{
res *= x;
}
return res;
}
/**
* @brief ATK-MD0280模块初始化
* @param 无
* @retval ATK_MD0280_EOK : ATK_MD0280模块初始化成功
* ATK_MD0280_ERROR: ATK_MD0280模块初始化失败
*/
uint8_t atk_md0280_init(void)
{
uint16_t chip_id;
atk_md0280_hw_init(); /* ATK-MD0280模块硬件初始化 */
atk_md0280_gpio_init(); /* ATK-MD0280模块GPIO接口初始化 */
chip_id = atk_md0280_get_chip_id(); /* 获取ATK-MD0280模块驱动器ID */
printf("atk_md0280_get_chip_id succeed!!\r\n");
if ((chip_id != ATK_MD0280_CHIP_ID1) && (chip_id != ATK_MD0280_CHIP_ID2))
{
return ATK_MD0280_ERROR;
}
else
{
g_atk_md0280_sta.chip_id = chip_id;
g_atk_md0280_sta.width = ATK_MD0280_LCD_WIDTH;
g_atk_md0280_sta.height = ATK_MD0280_LCD_HEIGHT;
}
printf("Start SET!!!\r\n");
atk_md0280_reg_init();
printf("atk_md0280_reg_init succeed!!\r\n");
atk_md0280_set_disp_dir(ATK_MD0280_LCD_DISP_DIR_0);
printf("atk_md0280_set_disp_dir succeed!!\r\n");
atk_md0280_clear(ATK_MD0280_WHITE);
printf("atk_md0280_clear succeed!!\r\n");
atk_md0280_display_on();
printf("atk_md0280_display_on succeed!!\r\n");
atk_md0280_backlight_on();
printf("atk_md0280_backlight_on succeed!!\r\n");
#if (ATK_MD0280_USING_TOUCH != 0)
atk_md0280_touch_init();
#endif
printf("atk_md0280_init succeed!!!\r\n");
return ATK_MD0280_EOK;
}
/**
* @brief 获取ATK-MD0280模块LCD宽度
* @param 无
* @retval ATK-MD0280模块LCD宽度
*/
uint16_t atk_md0280_get_lcd_width(void)
{
return g_atk_md0280_sta.width;
}
/**
* @brief 获取ATK-MD0280模块LCD高度
* @param 无
* @retval ATK-MD0280模块LCD高度
*/
uint16_t atk_md0280_get_lcd_height(void)
{
return g_atk_md0280_sta.height;
}
/**
* @brief 开启ATK-MD0280模块LCD背光
* @param 无
* @retval 无
*/
void atk_md0280_backlight_on(void)
{
ATK_MD0280_BL(1);
}
/**
* @brief 关闭ATK-MD0280模块LCD背光
* @param 无
* @retval 无
*/
void atk_md0280_backlight_off(void)
{
ATK_MD0280_BL(0);
}
/**
* @brief 开启ATK-MD0280模块LCD显示
* @param 无
* @retval 无
*/
void atk_md0280_display_on(void)
{
atk_md0280_gpio_write_cmd(0x29);
}
/**
* @brief 关闭ATK-MD0280模块LCD显示
* @param 无
* @retval 无
*/
void atk_md0280_display_off(void)
{
atk_md0280_gpio_write_cmd(0x28);
}
/**
* @brief 设置ATK-MD0280模块LCD扫描方向
* @param scan_dir: ATK_MD0280_LCD_SCAN_DIR_L2R_U2D: 从左到右,从上到下
* ATK_MD0280_LCD_SCAN_DIR_L2R_D2U: 从左到右,从下到上
* ATK_MD0280_LCD_SCAN_DIR_R2L_U2D: 从右到左,从上到下
* ATK_MD0280_LCD_SCAN_DIR_R2L_D2U: 从右到左,从下到上
* ATK_MD0280_LCD_SCAN_DIR_U2D_L2R: 从上到下,从左到右
* ATK_MD0280_LCD_SCAN_DIR_U2D_R2L: 从上到下,从右到左
* ATK_MD0280_LCD_SCAN_DIR_D2U_L2R: 从下到上,从左到右
* ATK_MD0280_LCD_SCAN_DIR_D2U_R2L: 从下到上,从右到左
* @retval ATK_MD0280_EOK : 设置ATK-MD0280模块LCD扫描方向成功
* ATK_MD0280_ERROR : 设置ATK-MD0280模块LCD扫描方向失败
* ATK_MD0280_EINVAL: 传入参数错误
*/
uint8_t atk_md0280_set_scan_dir(atk_md0280_lcd_scan_dir_t scan_dir)
{
uint16_t reg36;
switch (g_atk_md0280_sta.disp_dir)
{
case ATK_MD0280_LCD_DISP_DIR_0:
{
reg36 = (uint16_t)scan_dir;
break;
}
case ATK_MD0280_LCD_DISP_DIR_90:
{
switch (scan_dir)
{
case ATK_MD0280_LCD_SCAN_DIR_L2R_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_L2R_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_L2R;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_L2R;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_U2D;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_D2U;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_U2D;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_D2U;
break;
}
default:
{
return ATK_MD0280_EINVAL;
}
}
break;
}
case ATK_MD0280_LCD_DISP_DIR_180:
{
switch (scan_dir)
{
case ATK_MD0280_LCD_SCAN_DIR_L2R_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_D2U;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_L2R_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_U2D;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_D2U;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_U2D;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_L2R;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_L2R;
break;
}
default:
{
return ATK_MD0280_EINVAL;
}
}
break;
}
case ATK_MD0280_LCD_DISP_DIR_270:
{
switch (scan_dir)
{
case ATK_MD0280_LCD_SCAN_DIR_L2R_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_L2R;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_L2R_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_D2U_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_U2D:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_L2R;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_R2L_D2U:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_U2D_R2L;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_D2U;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_U2D_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_L2R_U2D;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_L2R:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_D2U;
break;
}
case ATK_MD0280_LCD_SCAN_DIR_D2U_R2L:
{
reg36 = ATK_MD0280_LCD_SCAN_DIR_R2L_U2D;
break;
}
default:
{
return ATK_MD0280_EINVAL;
}
}
break;
}
default:
{
return ATK_MD0280_ERROR;
}
}
g_atk_md0280_sta.scan_dir = (atk_md0280_lcd_scan_dir_t)reg36;
atk_md0280_gpio_write_reg(0x36, reg36);
atk_md0280_set_column_address(0, g_atk_md0280_sta.width - 1);
atk_md0280_set_page_address(0, g_atk_md0280_sta.height - 1);
return ATK_MD0280_EOK;
}
/**
* @brief 设置ATK-MD0280模块LCD显示方向
* @param disp_dir: ATK_MD0280_LCD_DISP_DIR_0 : LCD顺时针旋转0°显示内容
* ATK_MD0280_LCD_DISP_DIR_90 : LCD顺时针旋转90°显示内容
* ATK_MD0280_LCD_DISP_DIR_180: LCD顺时针旋转180°显示内容
* ATK_MD0280_LCD_DISP_DIR_270: LCD顺时针旋转270°显示内容
* @retval ATK_MD0280_EOK : 设置ATK-MD0280模块LCD显示方向成功
* ATK_MD0280_EINVAL: 传入参数错误
*/
uint8_t atk_md0280_set_disp_dir(atk_md0280_lcd_disp_dir_t disp_dir)
{
switch (disp_dir)
{
case ATK_MD0280_LCD_DISP_DIR_0:
{
g_atk_md0280_sta.width = ATK_MD0280_LCD_WIDTH;
g_atk_md0280_sta.height = ATK_MD0280_LCD_HEIGHT;
break;
}
case ATK_MD0280_LCD_DISP_DIR_90:
{
g_atk_md0280_sta.width = ATK_MD0280_LCD_HEIGHT;
g_atk_md0280_sta.height = ATK_MD0280_LCD_WIDTH;
break;
}
case ATK_MD0280_LCD_DISP_DIR_180:
{
g_atk_md0280_sta.width = ATK_MD0280_LCD_WIDTH;
g_atk_md0280_sta.height = ATK_MD0280_LCD_HEIGHT;
break;
}
case ATK_MD0280_LCD_DISP_DIR_270:
{
g_atk_md0280_sta.width = ATK_MD0280_LCD_HEIGHT;
g_atk_md0280_sta.height = ATK_MD0280_LCD_WIDTH;
break;
}
default:
{
return ATK_MD0280_EINVAL;
}
}
g_atk_md0280_sta.disp_dir = disp_dir;
atk_md0280_set_scan_dir(ATK_MD0280_LCD_SCAN_DIR_L2R_U2D);
return ATK_MD0280_EOK;
}
/**
* @brief 获取ATK-MD0280模块LCD扫描方向
* @param 无
* @retval ATK-MD0280模块LCD扫描方向
*/
atk_md0280_lcd_scan_dir_t atk_md0280_get_scan_dir(void)
{
return g_atk_md0280_sta.scan_dir;
}
/**
* @brief 获取ATK-MD0280模块LCD显示方向
* @param 无
* @retval ATK-MD0280模块LCD显示方向
*/
atk_md0280_lcd_disp_dir_t atk_md0280_get_disp_dir(void)
{
return g_atk_md0280_sta.disp_dir;
}
/**
* @brief ATK-MD0280模块LCD区域填充
* @param xs : 区域起始X坐标
* ys : 区域起始Y坐标
* xe : 区域终止X坐标
* ye : 区域终止Y坐标
* color: 区域填充颜色
* @retval 无
*/
void atk_md0280_fill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color)
{
uint16_t x_index;
uint16_t y_index;
atk_md0280_set_column_address(xs, xe);
atk_md0280_set_page_address(ys, ye);
atk_md0280_start_write_memory();
for (y_index=ys; y_index<=ye; y_index++)
{
for (x_index=xs; x_index<= xe; x_index++)
{
atk_md0280_gpio_write_dat(color);
}
}
}
/**
* @brief ATK-MD0280模块LCD清屏
* @param color: 清屏颜色
* @retval 无
*/
void atk_md0280_clear(uint16_t color)
{
atk_md0280_fill(0, 0, ATK_MD0280_LCD_WIDTH - 1, ATK_MD0280_LCD_HEIGHT - 1, color);
}
/**
* @brief ATK-MD0280模块LCD画点
* @param x : 待画点的X坐标
* y : 待画点的Y坐标
* color: 待画点的颜色
* @retval 无
*/
void atk_md0280_draw_point(uint16_t x, uint16_t y, uint16_t color)
{
atk_md0280_set_column_address(x, x);
atk_md0280_set_page_address(y, y);
atk_md0280_start_write_memory();
atk_md0280_gpio_write_dat(color);
}
/**
* @brief ATK-MD0280模块LCD读点
* @param x : 待读点的X坐标
* y : 待读点的Y坐标
* @retval 待读点的颜色
*/
uint16_t atk_md0280_read_point(uint16_t x, uint16_t y)
{
uint16_t color;
uint8_t color_r;
uint8_t color_g;
uint8_t color_b;
if ((x >= g_atk_md0280_sta.width) || (y >= g_atk_md0280_sta.height))
{
return ATK_MD0280_EINVAL;
}
atk_md0280_set_column_address(x, x);
atk_md0280_set_page_address(y, y);
atk_md0280_start_read_memory();
color = atk_md0280_gpio_read_dat(); /* Dummy */
color = atk_md0280_gpio_read_dat(); /* []: R, []:G */
color_r = (uint8_t)(color >> 11) & 0x1F;
color_g = (uint8_t)(color >> 2) & 0x3F;
color = atk_md0280_gpio_read_dat(); /* []: B */
color_b = (uint8_t)(color >> 11) & 0x1F;
return (uint16_t)(color_r << 11) | (color_g << 5) | color_b;
}
/**
* @brief ATK-MD0280模块LCD画线段
* @param x1 : 待画线段端点1的X坐标
* y1 : 待画线段端点1的Y坐标
* x2 : 待画线段端点2的X坐标
* y2 : 待画线段端点2的Y坐标
* color: 待画线段的颜色
* @retval 无
*/
void atk_md0280_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
uint16_t x_delta;
uint16_t y_delta;
int16_t x_sign;
int16_t y_sign;
int16_t error;
int16_t error2;
x_delta = (x1 < x2) ? (x2 - x1) : (x1 - x2);
y_delta = (y1 < y2) ? (y2 - y1) : (y1 - y2);
x_sign = (x1 < x2) ? 1 : -1;
y_sign = (y1 < y2) ? 1 : -1;
error = x_delta - y_delta;
atk_md0280_draw_point(x2, y2, color);
while ((x1 != x2) || (y1 != y2))
{
atk_md0280_draw_point(x1, y1, color);
error2 = error << 1;
if (error2 > -y_delta)
{
error -= y_delta;
x1 += x_sign;
}
if (error2 < x_delta)
{
error += x_delta;
y1 += y_sign;
}
}
}
/**
* @brief ATK-MD0280模块LCD画矩形框
* @param x1 : 待画矩形框端点1的X坐标
* y1 : 待画矩形框端点1的Y坐标
* x2 : 待画矩形框端点2的X坐标
* y2 : 待画矩形框端点2的Y坐标
* color: 待画矩形框的颜色
* @retval 无
*/
void atk_md0280_draw_rect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
atk_md0280_draw_line(x1, y1, x2, y1, color);
atk_md0280_draw_line(x1, y2, x2, y2, color);
atk_md0280_draw_line(x1, y1, x1, y2, color);
atk_md0280_draw_line(x2, y1, x2, y2, color);
}
/**
* @brief ATK-MD0280模块LCD画圆形框
* @param x : 待画圆形框原点的X坐标
* y : 待画圆形框原点的Y坐标
* r : 待画圆形框的半径
* color: 待画圆形框的颜色
* @retval 无
*/
void atk_md0280_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
{
int32_t x_t;
int32_t y_t;
int32_t error;
int32_t error2;
x_t = -r;
y_t = 0;
error = 2 - 2 * r;
do {
atk_md0280_draw_point(x - x_t, y + y_t, color);
atk_md0280_draw_point(x + x_t, y + y_t, color);
atk_md0280_draw_point(x + x_t, y - y_t, color);
atk_md0280_draw_point(x - x_t, y - y_t, color);
error2 = error;
if (error2 <= y_t)
{
y_t++;
error = error + (y_t * 2 + 1);
if ((-x_t == y_t) && (error2 <= x_t))
{
error2 = 0;
}
}
if (error2 > x_t)
{
x_t++;
error = error + (x_t * 2 + 1);
}
} while (x_t <= 0);
}
/**
* @brief ATK-MD0280模块LCD显示1个字符
* @param x : 待显示字符的X坐标
* y : 待显示字符的Y坐标
* ch : 待显示字符
* font : 待显示字符的字体
* color: 待显示字符的颜色
* @retval 无
*/
void atk_md0280_show_char(uint16_t x, uint16_t y, char ch, atk_md0280_lcd_font_t font, uint16_t color)
{
const uint8_t *ch_code;
uint8_t ch_width;
uint8_t ch_height;
uint8_t ch_size;
uint8_t ch_offset;
uint8_t byte_index;
uint8_t byte_code;
uint8_t bit_index;
uint8_t width_index = 0;
uint8_t height_index = 0;
ch_offset = ch - ' ';
switch (font)
{
#if (ATK_MD0280_FONT_12 != 0)
case ATK_MD0280_LCD_FONT_12:
{
ch_code = atk_md0280_font_1206[];
ch_width = ATK_MD0280_FONT_12_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_12_CHAR_HEIGHT;
ch_size = ATK_MD0280_FONT_12_CHAR_SIZE;
break;
}
#endif
#if (ATK_MD0280_FONT_16 != 0)
case ATK_MD0280_LCD_FONT_16:
{
ch_code = atk_md0280_font_1608[];
ch_width = ATK_MD0280_FONT_16_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_16_CHAR_HEIGHT;
ch_size = ATK_MD0280_FONT_16_CHAR_SIZE;
break;
}
#endif
#if (ATK_MD0280_FONT_24 != 0)
case ATK_MD0280_LCD_FONT_24:
{
ch_code = atk_md0280_font_2412[];
ch_width = ATK_MD0280_FONT_24_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_24_CHAR_HEIGHT;
ch_size = ATK_MD0280_FONT_24_CHAR_SIZE;
break;
}
#endif
#if (ATK_MD0280_FONT_32 != 0)
case ATK_MD0280_LCD_FONT_32:
{
ch_code = atk_md0280_font_3216[];
ch_width = ATK_MD0280_FONT_32_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_32_CHAR_HEIGHT;
ch_size = ATK_MD0280_FONT_32_CHAR_SIZE;
break;
}
#endif
default:
{
return;
}
}
if ((x + ch_width > ATK_MD0280_LCD_WIDTH) || (y + ch_height > ATK_MD0280_LCD_HEIGHT))
{
return;
}
for (byte_index=0; byte_index<ch_size; byte_index++)
{
byte_code = ch_code[];
for (bit_index=0; bit_index<8; bit_index++)
{
if ((byte_code & 0x80) != 0)
{
atk_md0280_draw_point(x + width_index, y + height_index, color);
}
width_index++;
if (width_index == ch_width)
{
width_index = 0;
height_index++;
break;
}
byte_code <<= 1;
}
}
}
/**
* @brief ATK-MD0280模块LCD显示字符串
* @note 会自动换行和换页
* @param x : 待显示字符串的X坐标
* y : 待显示字符串的Y坐标
* width : 待显示字符串的显示高度
* height: 待显示字符串的显示宽度
* str : 待显示字符串
* font : 待显示字符串的字体
* color : 待显示字符串的颜色
* @retval 无
*/
void atk_md0280_show_string(uint16_t x, uint16_t y, uint16_t width, uint16_t height, char *str, atk_md0280_lcd_font_t font, uint16_t color)
{
uint8_t ch_width;
uint8_t ch_height;
uint16_t x_raw;
uint16_t y_raw;
uint16_t x_limit;
uint16_t y_limit;
switch (font)
{
#if (ATK_MD0280_FONT_12 != 0)
case ATK_MD0280_LCD_FONT_12:
{
ch_width = ATK_MD0280_FONT_12_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_12_CHAR_HEIGHT;
break;
}
#endif
#if (ATK_MD0280_FONT_16 != 0)
case ATK_MD0280_LCD_FONT_16:
{
ch_width = ATK_MD0280_FONT_16_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_16_CHAR_HEIGHT;
break;
}
#endif
#if (ATK_MD0280_FONT_24 != 0)
case ATK_MD0280_LCD_FONT_24:
{
ch_width = ATK_MD0280_FONT_24_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_24_CHAR_HEIGHT;
break;
}
#endif
#if (ATK_MD0280_FONT_32 != 0)
case ATK_MD0280_LCD_FONT_32:
{
ch_width = ATK_MD0280_FONT_32_CHAR_WIDTH;
ch_height = ATK_MD0280_FONT_32_CHAR_HEIGHT;
break;
}
#endif
default:
{
return;
}
}
x_raw = x;
y_raw = y;
x_limit = ((x + width + 1) > ATK_MD0280_LCD_WIDTH) ? ATK_MD0280_LCD_WIDTH : (x + width + 1);
y_limit = ((y + height + 1) > ATK_MD0280_LCD_HEIGHT) ? ATK_MD0280_LCD_HEIGHT : (y + height + 1);
while ((*str >= ' ') && (*str <= '~'))
{
if (x + ch_width >= x_limit)
{
x = x_raw;
y += ch_height;
}
if (y + ch_height >= y_limit)
{
y = x_raw;
x = y_raw;
}
atk_md0280_show_char(x, y, *str, font, color);
x += ch_width;
str++;
}
}
/**
* @brief ATK-MD0280模块LCD显示数字,可控制显示高位0
* @param x : 待显示数字的X坐标
* y : 待显示数字的Y坐标
* num : 待显示数字
* len : 待显示数字的位数
* mode : ATK_MD0280_NUM_SHOW_NOZERO: 数字高位0不显示
* ATK_MD0280_NUM_SHOW_ZERO : 数字高位0显示
* font : 待显示数字的字体
* color: 待显示数字的颜色
* @retval 无
*/
void atk_md0280_show_xnum(uint16_t x, uint16_t y, uint32_t num, uint8_t len, atk_md0280_num_mode_t mode, atk_md0280_lcd_font_t font, uint16_t color)
{
uint8_t ch_width;
uint8_t len_index;
uint8_t num_index;
uint8_t first_nozero = 0;
char pad;
switch (font)
{
#if (ATK_MD0280_FONT_12 != 0)
case ATK_MD0280_LCD_FONT_12:
{
ch_width = ATK_MD0280_FONT_12_CHAR_WIDTH;
break;
}
#endif
#if (ATK_MD0280_FONT_16 != 0)
case ATK_MD0280_LCD_FONT_16:
{
ch_width = ATK_MD0280_FONT_16_CHAR_WIDTH;
break;
}
#endif
#if (ATK_MD0280_FONT_24 != 0)
case ATK_MD0280_LCD_FONT_24:
{
ch_width = ATK_MD0280_FONT_24_CHAR_WIDTH;
break;
}
#endif
#if (ATK_MD0280_FONT_32 != 0)
case ATK_MD0280_LCD_FONT_32:
{
ch_width = ATK_MD0280_FONT_32_CHAR_WIDTH;
break;
}
#endif
default:
{
return;
}
}
switch (mode)
{
case ATK_MD0280_NUM_SHOW_NOZERO:
{
pad = ' ';
break;
}
case ATK_MD0280_NUM_SHOW_ZERO:
{
pad = '0';
break;
}
default:
{
return;
}
}
for (len_index=0; len_index<len; len_index++)
{
num_index = (num / atk_md0280_pow(10, len - len_index - 1)) % 10;
if ((first_nozero == 0) && (len_index < (len - 1)))
{
if (num_index == 0)
{
atk_md0280_show_char(x + ch_width * len_index, y, pad, font, color);
continue;
}
else
{
first_nozero = 1;
}
}
atk_md0280_show_char(x + ch_width * len_index, y, num_index + '0', font, color);
}
}
/**
* @brief ATK-MD0280模块LCD显示数字,不显示高位0
* @param x : 待显示数字的X坐标
* y : 待显示数字的Y坐标
* num : 待显示数字
* len : 待显示数字的位数
* font : 待显示数字的字体
* color: 待显示数字的颜色
* @retval 无
*/
void atk_md0280_show_num(uint16_t x, uint16_t y, uint32_t num, uint8_t len, atk_md0280_lcd_font_t font, uint16_t color)
{
atk_md0280_show_xnum(x, y, num, len, ATK_MD0280_NUM_SHOW_NOZERO, font, color);
}
/**
* @brief ATK-MD0280模块LCD图片
* @note 图片取模方式: 水平扫描、RGB565、高位在前
* @param x : 待显示图片的X坐标
* y : 待显示图片的Y坐标
* width : 待显示图片的宽度
* height: 待显示图片的高度
* pic : 待显示图片数组首地址
* @retval 无
*/
void atk_md0280_show_pic(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *pic)
{
uint16_t x_index;
uint16_t y_index;
if ((x + width > ATK_MD0280_LCD_WIDTH) || (y + height > ATK_MD0280_LCD_HEIGHT))
{
return;
}
atk_md0280_set_column_address(x, x + width - 1);
atk_md0280_set_page_address(y, y + height - 1);
atk_md0280_start_write_memory();
for (y_index=y; y_index<=(y + height); y_index++)
{
for (x_index=x; x_index<=(x + width); x_index++)
{
atk_md0280_gpio_write_dat(*pic);
pic++;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
atk_md0280_gpio.h
c
/**
****************************************************************************************************
* @file atk_md0280_gpio.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块GPIO接口驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#ifndef __ATK_MD0280_GPIO_H
#define __ATK_MD0280_GPIO_H
#include "board.h"
/*
CS A1
RS A0
WR A3
RD A4
RST A5
D0 A6
D1 A7
D2 C4
D3 C5
D4 B0
D5 B1
D6 E7
D7 E8
D8 E9
D9 E10
D10 E11
D11 E12
D12 E13
D13 E14
D14 E15
D15 B11
BL B10
MI B12
PEN B13
TCS B14
MO D8
CLK D10
*/
/* 引脚定义 */
#define ATK_MD0280_GPIO_RS_GPIO_RCU RCU_GPIOA
#define ATK_MD0280_GPIO_RS_GPIO_PORT GPIOA
#define ATK_MD0280_GPIO_RS_GPIO_PIN GPIO_PIN_0
#define ATK_MD0280_GPIO_CS_GPIO_RCU RCU_GPIOA
#define ATK_MD0280_GPIO_CS_GPIO_PORT GPIOA
#define ATK_MD0280_GPIO_CS_GPIO_PIN GPIO_PIN_1
#define ATK_MD0280_GPIO_RD_GPIO_RCU RCU_GPIOA
#define ATK_MD0280_GPIO_RD_GPIO_PORT GPIOA
#define ATK_MD0280_GPIO_RD_GPIO_PIN GPIO_PIN_4
#define ATK_MD0280_GPIO_WR_GPIO_RCU RCU_GPIOA
#define ATK_MD0280_GPIO_WR_GPIO_PORT GPIOA
#define ATK_MD0280_GPIO_WR_GPIO_PIN GPIO_PIN_3
#define ATK_MD0280_GPIO_DATA_GPIO_RCU1 RCU_GPIOA
#define ATK_MD0280_GPIO_DATA_GPIO_RCU2 RCU_GPIOC
#define ATK_MD0280_GPIO_DATA_GPIO_RCU3 RCU_GPIOB
#define ATK_MD0280_GPIO_DATA_GPIO_RCU4 RCU_GPIOE
#define ATK_MD0280_GPIO_DATA_D0_PORT GPIOA
#define ATK_MD0280_GPIO_DATA_D0_PIN GPIO_PIN_6
#define ATK_MD0280_GPIO_DATA_D1_PORT GPIOA
#define ATK_MD0280_GPIO_DATA_D1_PIN GPIO_PIN_7
#define ATK_MD0280_GPIO_DATA_D2_PORT GPIOC
#define ATK_MD0280_GPIO_DATA_D2_PIN GPIO_PIN_4
#define ATK_MD0280_GPIO_DATA_D3_PORT GPIOC
#define ATK_MD0280_GPIO_DATA_D3_PIN GPIO_PIN_5
#define ATK_MD0280_GPIO_DATA_D4_PORT GPIOB
#define ATK_MD0280_GPIO_DATA_D4_PIN GPIO_PIN_0
#define ATK_MD0280_GPIO_DATA_D5_PORT GPIOB
#define ATK_MD0280_GPIO_DATA_D5_PIN GPIO_PIN_1
#define ATK_MD0280_GPIO_DATA_D6_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D6_PIN GPIO_PIN_7
#define ATK_MD0280_GPIO_DATA_D7_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D7_PIN GPIO_PIN_8
#define ATK_MD0280_GPIO_DATA_D8_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D8_PIN GPIO_PIN_9
#define ATK_MD0280_GPIO_DATA_D9_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D9_PIN GPIO_PIN_10
#define ATK_MD0280_GPIO_DATA_D10_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D10_PIN GPIO_PIN_11
#define ATK_MD0280_GPIO_DATA_D11_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D11_PIN GPIO_PIN_12
#define ATK_MD0280_GPIO_DATA_D12_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D12_PIN GPIO_PIN_13
#define ATK_MD0280_GPIO_DATA_D13_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D13_PIN GPIO_PIN_14
#define ATK_MD0280_GPIO_DATA_D14_PORT GPIOE
#define ATK_MD0280_GPIO_DATA_D14_PIN GPIO_PIN_15
#define ATK_MD0280_GPIO_DATA_D15_PORT GPIOB
#define ATK_MD0280_GPIO_DATA_D15_PIN GPIO_PIN_11
/* IO操作 */
#define ATK_MD0280_GPIO_RS(x) gpio_bit_write(ATK_MD0280_GPIO_RS_GPIO_PORT, ATK_MD0280_GPIO_RS_GPIO_PIN, x)
#define ATK_MD0280_GPIO_CS(x) gpio_bit_write(ATK_MD0280_GPIO_CS_GPIO_PORT, ATK_MD0280_GPIO_CS_GPIO_PIN, x)
#define ATK_MD0280_GPIO_RD(x) gpio_bit_write(ATK_MD0280_GPIO_RD_GPIO_PORT, ATK_MD0280_GPIO_RD_GPIO_PIN, x)
#define ATK_MD0280_GPIO_WR(x) gpio_bit_write(ATK_MD0280_GPIO_WR_GPIO_PORT, ATK_MD0280_GPIO_WR_GPIO_PIN, x)
// x ? 置1 : 置0
#define PIN_HIGH_OR_LOW(port,gpio,x) {((x) ? (GPIO_OCTL(port)|=(uint32_t)(gpio)) : (GPIO_OCTL(port)&=~(uint32_t)(gpio)));}
// 先清除该位,空出位置 根据x判断是设置位还是清除位
#define BIT_DB15(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D15_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D15_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D15_PORT, ATK_MD0280_GPIO_DATA_D15_PIN, x) }
#define BIT_DB14(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D14_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D14_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D14_PORT, ATK_MD0280_GPIO_DATA_D14_PIN, x) }
#define BIT_DB13(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D13_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D13_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D13_PORT, ATK_MD0280_GPIO_DATA_D13_PIN, x) }
#define BIT_DB12(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D12_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D12_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D12_PORT, ATK_MD0280_GPIO_DATA_D12_PIN, x) }
#define BIT_DB11(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D11_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D11_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D11_PORT, ATK_MD0280_GPIO_DATA_D11_PIN, x) }
#define BIT_DB10(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D10_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D10_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D10_PORT, ATK_MD0280_GPIO_DATA_D10_PIN, x) }
#define BIT_DB9(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D9_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D9_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D9_PORT, ATK_MD0280_GPIO_DATA_D9_PIN, x) }
#define BIT_DB8(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D8_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D8_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D8_PORT, ATK_MD0280_GPIO_DATA_D8_PIN, x) }
#define BIT_DB7(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D7_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D7_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D7_PORT, ATK_MD0280_GPIO_DATA_D7_PIN, x) }
#define BIT_DB6(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D6_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D6_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D6_PORT, ATK_MD0280_GPIO_DATA_D6_PIN, x) }
#define BIT_DB5(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D5_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D5_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D5_PORT, ATK_MD0280_GPIO_DATA_D5_PIN, x) }
#define BIT_DB4(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D4_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D4_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D4_PORT, ATK_MD0280_GPIO_DATA_D4_PIN, x) }
#define BIT_DB3(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D3_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D3_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D3_PORT, ATK_MD0280_GPIO_DATA_D3_PIN, x) }
#define BIT_DB2(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D2_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D2_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D2_PORT, ATK_MD0280_GPIO_DATA_D2_PIN, x) }
#define BIT_DB1(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D1_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D1_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D1_PORT, ATK_MD0280_GPIO_DATA_D1_PIN, x) }
#define BIT_DB0(x) { GPIO_OCTL(ATK_MD0280_GPIO_DATA_D0_PORT) &= ((uint32_t)~(ATK_MD0280_GPIO_DATA_D0_PIN)); PIN_HIGH_OR_LOW( ATK_MD0280_GPIO_DATA_D0_PORT, ATK_MD0280_GPIO_DATA_D0_PIN, x) }
/* 操作函数 */
void atk_md0280_gpio_init(void); /* ATK-MD0280模块GPIO接口初始化 */
void atk_md0280_gpio_write_cmd(uint16_t cmd); /* ATK-MD0280模块通过GPIO接口写命令 */
void atk_md0280_gpio_write_dat(uint16_t dat); /* ATK-MD0280模块通过GPIO接口写数据 */
void atk_md0280_gpio_write_reg(uint16_t reg, uint16_t dat); /* ATK-MD0280模块通过GPIO接口写寄存器 */
uint16_t atk_md0280_gpio_read_dat(void); /* ATK-MD0280模块通过GPIO接口读数据 */
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
atk_md0280_gpio.c
c
/**
****************************************************************************************************
* @file atk_md0280_gpio.c
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块GPIO接口驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#include "atk_md0280_gpio.h"
/******************************************************************************
函数说明:LCD串行数据写入函数
入口数据:dat 要写入的串行数据
返回值: 无
******************************************************************************/
void LCD_Writ_Bus(uint16_t dat)
{
ATK_MD0280_GPIO_CS(0);
ATK_MD0280_GPIO_WR(0);
BIT_DB15( (dat>>15)&0x01 );
BIT_DB14( (dat>>14)&0x01 );
BIT_DB13( (dat>>13)&0x01 );
BIT_DB12( (dat>>12)&0x01 );
BIT_DB11( (dat>>11)&0x01 );
BIT_DB10( (dat>>10)&0x01 );
BIT_DB9( (dat>>9)&0x01 );
BIT_DB8( (dat>>8)&0x01 );
BIT_DB7( (dat>>7)&0x01 );
BIT_DB6( (dat>>6)&0x01 );
BIT_DB5( (dat>>5)&0x01 );
BIT_DB4( (dat>>4)&0x01 );
BIT_DB3( (dat>>3)&0x01 );
BIT_DB2( (dat>>2)&0x01 );
BIT_DB1( (dat>>1)&0x01 );
BIT_DB0( (dat>>0)&0x01 );
ATK_MD0280_GPIO_WR(1);
ATK_MD0280_GPIO_CS(1);
}
/******************************************************************************
函数说明:LCD串行数据读取函数
入口数据:无
返回值: 读取的数据
******************************************************************************/
uint16_t LCD_Read_Bus(void)
{
uint16_t data = 0;
ATK_MD0280_GPIO_CS(0);
ATK_MD0280_GPIO_RD(0);
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D15_PORT, ATK_MD0280_GPIO_DATA_D15_PIN) ) << 15 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D14_PORT, ATK_MD0280_GPIO_DATA_D14_PIN) ) << 14 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D13_PORT, ATK_MD0280_GPIO_DATA_D13_PIN) ) << 13 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D12_PORT, ATK_MD0280_GPIO_DATA_D12_PIN) ) << 12 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D11_PORT, ATK_MD0280_GPIO_DATA_D11_PIN) ) << 11 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D10_PORT, ATK_MD0280_GPIO_DATA_D10_PIN) ) << 10 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D9_PORT, ATK_MD0280_GPIO_DATA_D9_PIN) ) << 9 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D8_PORT, ATK_MD0280_GPIO_DATA_D8_PIN) ) << 8 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D7_PORT, ATK_MD0280_GPIO_DATA_D7_PIN) ) << 7 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D6_PORT, ATK_MD0280_GPIO_DATA_D6_PIN) ) << 6 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D5_PORT, ATK_MD0280_GPIO_DATA_D5_PIN) ) << 5 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D4_PORT, ATK_MD0280_GPIO_DATA_D4_PIN) ) << 4 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D3_PORT, ATK_MD0280_GPIO_DATA_D3_PIN) ) << 3 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D2_PORT, ATK_MD0280_GPIO_DATA_D2_PIN) ) << 2 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D1_PORT, ATK_MD0280_GPIO_DATA_D1_PIN) ) << 1 );
data |= ( ( gpio_input_bit_get(ATK_MD0280_GPIO_DATA_D0_PORT, ATK_MD0280_GPIO_DATA_D0_PIN) ) << 0 );
ATK_MD0280_GPIO_RD(1);
ATK_MD0280_GPIO_CS(1);
return data;
}
/**
* @brief ATK-MD0280模块GPIO接口初始化
* @param 无
* @retval 无
*/
void atk_md0280_gpio_init(void)
{
/* 使能时钟 */
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_GPIOC);
rcu_periph_clock_enable(RCU_GPIOD);
rcu_periph_clock_enable(RCU_GPIOE);
/* 初始化RS引脚 */
gpio_mode_set(ATK_MD0280_GPIO_RS_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_RS_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_RS_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_RS_GPIO_PIN);
/* 初始化CS引脚 */
gpio_mode_set(ATK_MD0280_GPIO_CS_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_CS_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_CS_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_CS_GPIO_PIN);
/* 初始化RD引脚 */
gpio_mode_set(ATK_MD0280_GPIO_RD_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_RD_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_RD_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_RD_GPIO_PIN);
/* 初始化WR引脚 */
gpio_mode_set(ATK_MD0280_GPIO_WR_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_WR_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_WR_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_WR_GPIO_PIN);
/* 初始化DATA引脚 */
// D0
gpio_mode_set(ATK_MD0280_GPIO_DATA_D0_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D0_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D0_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D0_PIN);
// D1
gpio_mode_set(ATK_MD0280_GPIO_DATA_D1_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D1_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D1_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D1_PIN);
// D2
gpio_mode_set(ATK_MD0280_GPIO_DATA_D2_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D2_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D2_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D2_PIN);
// D3
gpio_mode_set(ATK_MD0280_GPIO_DATA_D3_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D3_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D3_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D3_PIN);
// D4
gpio_mode_set(ATK_MD0280_GPIO_DATA_D4_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D4_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D4_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D4_PIN);
// D5
gpio_mode_set(ATK_MD0280_GPIO_DATA_D5_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D5_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D5_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D5_PIN);
// D6
gpio_mode_set(ATK_MD0280_GPIO_DATA_D6_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D6_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D6_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D6_PIN);
// D7
gpio_mode_set(ATK_MD0280_GPIO_DATA_D7_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D7_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D7_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D7_PIN);
// D8
gpio_mode_set(ATK_MD0280_GPIO_DATA_D8_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D8_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D8_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D8_PIN);
// D9
gpio_mode_set(ATK_MD0280_GPIO_DATA_D9_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D9_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D9_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D9_PIN);
// D10
gpio_mode_set(ATK_MD0280_GPIO_DATA_D10_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D10_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D10_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D10_PIN);
// D11
gpio_mode_set(ATK_MD0280_GPIO_DATA_D11_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D11_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D11_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D11_PIN);
// D12
gpio_mode_set(ATK_MD0280_GPIO_DATA_D12_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D12_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D12_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D12_PIN);
// D13
gpio_mode_set(ATK_MD0280_GPIO_DATA_D13_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D13_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D13_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D13_PIN);
// D14
gpio_mode_set(ATK_MD0280_GPIO_DATA_D14_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D14_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D14_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D14_PIN);
// D15
gpio_mode_set(ATK_MD0280_GPIO_DATA_D15_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D15_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D15_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D15_PIN);
ATK_MD0280_GPIO_RS(1);
ATK_MD0280_GPIO_CS(1);
ATK_MD0280_GPIO_RD(1);
ATK_MD0280_GPIO_WR(1);
LCD_Writ_Bus(0xFFFF);
}
/**
* @brief ATK-MD0280模块通过GPIO接口写命令
* @param cmd: 待写命令
* @retval 无
*/
void atk_md0280_gpio_write_cmd(uint16_t cmd)
{
ATK_MD0280_GPIO_RS(0);
ATK_MD0280_GPIO_CS(0);
LCD_Writ_Bus(cmd);
ATK_MD0280_GPIO_WR(0);
ATK_MD0280_GPIO_WR(1);
ATK_MD0280_GPIO_CS(1);
}
/**
* @brief ATK-MD0280模块通过GPIO接口写数据
* @param dat: 待写数据
* @retval 无
*/
void atk_md0280_gpio_write_dat(uint16_t dat)
{
ATK_MD0280_GPIO_RS(1);
ATK_MD0280_GPIO_CS(0);
LCD_Writ_Bus(dat);
ATK_MD0280_GPIO_WR(0);
ATK_MD0280_GPIO_WR(1);
ATK_MD0280_GPIO_CS(1);
}
/**
* @brief ATK-MD0280模块通过GPIO接口写寄存器
* @param reg: 待操作寄存器
* dat: 待写数据
* @retval 无
*/
void atk_md0280_gpio_write_reg(uint16_t reg, uint16_t dat)
{
atk_md0280_gpio_write_cmd(reg);
atk_md0280_gpio_write_dat(dat);
}
/**
* @brief ATK-MD0280模块通过GPIO接口读数据
* @param 无
* @retval 读取到的数据
*/
uint16_t atk_md0280_gpio_read_dat(void)
{
uint16_t dat;
// D0
gpio_mode_set(ATK_MD0280_GPIO_DATA_D0_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D0_PIN);
// D1
gpio_mode_set(ATK_MD0280_GPIO_DATA_D1_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D1_PIN);
// D2
gpio_mode_set(ATK_MD0280_GPIO_DATA_D2_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D2_PIN);
// D3
gpio_mode_set(ATK_MD0280_GPIO_DATA_D3_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D3_PIN);
// D4
gpio_mode_set(ATK_MD0280_GPIO_DATA_D4_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D4_PIN);
// D5
gpio_mode_set(ATK_MD0280_GPIO_DATA_D5_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D5_PIN);
// D6
gpio_mode_set(ATK_MD0280_GPIO_DATA_D6_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D6_PIN);
// D7
gpio_mode_set(ATK_MD0280_GPIO_DATA_D7_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D7_PIN);
// D8
gpio_mode_set(ATK_MD0280_GPIO_DATA_D8_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D8_PIN);
// D9
gpio_mode_set(ATK_MD0280_GPIO_DATA_D9_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D9_PIN);
// D10
gpio_mode_set(ATK_MD0280_GPIO_DATA_D10_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D10_PIN);
// D11
gpio_mode_set(ATK_MD0280_GPIO_DATA_D11_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D11_PIN);
// D12
gpio_mode_set(ATK_MD0280_GPIO_DATA_D12_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D12_PIN);
// D13
gpio_mode_set(ATK_MD0280_GPIO_DATA_D13_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D13_PIN);
// D14
gpio_mode_set(ATK_MD0280_GPIO_DATA_D14_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D14_PIN);
// D15
gpio_mode_set(ATK_MD0280_GPIO_DATA_D15_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_GPIO_DATA_D15_PIN);
ATK_MD0280_GPIO_RS(1);
delay_us(1);
dat = LCD_Read_Bus();
// D0
gpio_mode_set(ATK_MD0280_GPIO_DATA_D0_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D0_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D0_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D0_PIN);
// D1
gpio_mode_set(ATK_MD0280_GPIO_DATA_D1_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D1_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D1_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D1_PIN);
// D2
gpio_mode_set(ATK_MD0280_GPIO_DATA_D2_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D2_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D2_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D2_PIN);
// D3
gpio_mode_set(ATK_MD0280_GPIO_DATA_D3_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D3_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D3_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D3_PIN);
// D4
gpio_mode_set(ATK_MD0280_GPIO_DATA_D4_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D4_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D4_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D4_PIN);
// D5
gpio_mode_set(ATK_MD0280_GPIO_DATA_D5_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D5_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D5_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D5_PIN);
// D6
gpio_mode_set(ATK_MD0280_GPIO_DATA_D6_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D6_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D6_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D6_PIN);
// D7
gpio_mode_set(ATK_MD0280_GPIO_DATA_D7_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D7_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D7_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D7_PIN);
// D8
gpio_mode_set(ATK_MD0280_GPIO_DATA_D8_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D8_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D8_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D8_PIN);
// D9
gpio_mode_set(ATK_MD0280_GPIO_DATA_D9_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D9_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D9_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D9_PIN);
// D10
gpio_mode_set(ATK_MD0280_GPIO_DATA_D10_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D10_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D10_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D10_PIN);
// D11
gpio_mode_set(ATK_MD0280_GPIO_DATA_D11_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D11_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D11_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D11_PIN);
// D12
gpio_mode_set(ATK_MD0280_GPIO_DATA_D12_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D12_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D12_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D12_PIN);
// D13
gpio_mode_set(ATK_MD0280_GPIO_DATA_D13_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D13_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D13_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D13_PIN);
// D14
gpio_mode_set(ATK_MD0280_GPIO_DATA_D14_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D14_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D14_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D14_PIN);
// D15
gpio_mode_set(ATK_MD0280_GPIO_DATA_D15_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_GPIO_DATA_D15_PIN);
gpio_output_options_set(ATK_MD0280_GPIO_DATA_D15_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_GPIO_DATA_D15_PIN);
return dat;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
atk_md0280_touch.h
c
/**
****************************************************************************************************
* @file atk_md0280_touch.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块触摸驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#ifndef __ATK_MD0280_TOUCH_H
#define __ATK_MD0280_TOUCH_H
#include "atk_md0280.h"
#if (ATK_MD0280_USING_TOUCH != 0)
#define ATK_MD0280_TOUCH_READ_TIMES 5 /* 定义单次获取坐标读取的次数 */
#define ATK_MD0280_TOUCH_READ_DISCARD 1 /* 定义单次获取坐标丢弃的最大最小值的数量 */
#define ATK_MD0280_TOUCH_READ_RANGE 50 /* 定义单次获取坐标读取的两次值之间误差的最大值 */
/* 引脚定义 */
#define ATK_MD0280_TOUCH_PEN_GPIO_RCU RCU_GPIOB
#define ATK_MD0280_TOUCH_PEN_GPIO_PORT GPIOB
#define ATK_MD0280_TOUCH_PEN_GPIO_PIN GPIO_PIN_13
/* IO操作 */
#define ATK_MD0280_TOUCH_READ_PEN() gpio_input_bit_get(ATK_MD0280_TOUCH_PEN_GPIO_PORT, ATK_MD0280_TOUCH_PEN_GPIO_PIN)
/* 错误代码 */
#define ATK_MD0280_TOUCH_EOK 0 /* 没有错误 */
#define ATK_MD0280_TOUCH_ERROR 1
#define ATK_MD0280_TOUCH_EMPTY 2 /* 空 */
/* 操作函数 */
void atk_md0280_touch_init(void); /* ATK-MD0280模块触摸初始化 */
uint8_t atk_md0280_touch_scan(uint16_t *x, uint16_t *y); /* ATK-MD0280模块触摸扫描 */
#endif /* ATK_MD0280_USING_TOUCH */
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
atk_md0280_touch.c
c
/**
****************************************************************************************************
* @file atk_md0280_touch.c
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块触摸驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#include "atk_md0280_touch.h"
#if (ATK_MD0280_USING_TOUCH != 0)
#include "atk_md0280_touch_spi.h"
#include <stdlib.h>
#include "board.h"
/* 获取X/Y坐标ADC值的命令 */
#define ATK_MD0280_TOUCH_CMD_X 0xD0
#define ATK_MD0280_TOUCH_CMD_Y 0x90
/* ATK-MD0280模块触摸状态数据结构体 */
static struct
{
struct
{
float x;
float y;
} fac; /* 校准比例因子 */
struct
{
uint16_t x;
uint16_t y;
} center; /* 中心坐标的ADC值 */
} g_atk_md0280_touch_sta = {0};
/**
* @brief ATK-MD0280模块触摸硬件初始化
* @param 无
* @retval 无
*/
static void atk_md0280_touch_hw_init(void)
{
/* 使能时钟 */
rcu_periph_clock_enable(ATK_MD0280_TOUCH_PEN_GPIO_RCU);
/* 初始化PEN引脚 */
gpio_mode_set(ATK_MD0280_TOUCH_PEN_GPIO_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_TOUCH_PEN_GPIO_PIN);
}
/**
* @brief 获取ATK-MD0280模块触摸的X/Y轴ADC值
* @note 连续读取ATK_MD0280_TOUCH_READ_TIMES次,
* 并丢弃最大最小值各ATK_MD0280_TOUCH_READ_DISCARD个,
* 最后返回剩余的均值
* @param cmd: ATK_MD0280_TOUCH_CMD_X: 获取X轴的ADC值(LCD显示内容未旋转)
* ATK_MD0280_TOUCH_CMD_Y: 获取Y轴的ADC值(LCD显示内容未旋转)
* @retval 获取到的触摸ADC值
*/
static uint16_t atk_md0280_touch_get_adc(uint8_t cmd)
{
uint16_t dat[];
uint8_t dat_index;
uint8_t dat_index2;
uint16_t dat_tmp;
uint16_t dat_sum = 0;
for (dat_index=0; dat_index<ATK_MD0280_TOUCH_READ_TIMES; dat_index++)
{
dat[] = atk_md0280_touch_spi_read(cmd);
}
for (dat_index=0; dat_index<(ATK_MD0280_TOUCH_READ_TIMES-1); dat_index++)
{
for (dat_index2=(dat_index+1); dat_index2<ATK_MD0280_TOUCH_READ_TIMES; dat_index2++)
{
if (dat[] > dat[])
{
dat_tmp = dat[];
dat[] = dat[];
dat[] = dat_tmp;
}
}
}
for (dat_index=ATK_MD0280_TOUCH_READ_DISCARD; dat_index<(ATK_MD0280_TOUCH_READ_TIMES-ATK_MD0280_TOUCH_READ_DISCARD); dat_index++)
{
dat_sum += dat[];
}
return (dat_sum / (ATK_MD0280_TOUCH_READ_TIMES - (ATK_MD0280_TOUCH_READ_DISCARD << 1)));
}
/**
* @brief 获取ATK-MD0280模块触摸的X/Y轴ADC值
* @note 连续读取两次,直至两次读取的插值小于ATK_MD0280_TOUCH_READ_RANGE,
* 后返回均值
* @param cmd: ATK_MD0280_TOUCH_CMD_X: 获取X轴的ADC值(LCD显示内容未旋转)
* ATK_MD0280_TOUCH_CMD_Y: 获取Y轴的ADC值(LCD显示内容未旋转)
* @retval 获取到的触摸ADC值
*/
static uint16_t atk_md0280_touch_get_adc2(uint8_t cmd)
{
uint16_t dat1;
uint16_t dat2;
uint16_t delta;
do {
dat1 = atk_md0280_touch_get_adc(cmd);
dat2 = atk_md0280_touch_get_adc(cmd);
if (dat1 > dat2)
{
delta = dat1 - dat2;
}
else
{
delta = dat2 - dat1;
}
} while (delta > ATK_MD0280_TOUCH_READ_RANGE);
return ((dat1 + dat2) >> 1);
}
/**
* @brief 绘画ATK-MD0280模块触摸校准触摸点
* @param x : 待画校准触摸点的X坐标
* y : 待画校准触摸点的Y坐标
* color: 待画校准触摸点的颜色
* @retval 无
*/
static void atk_md0280_touch_draw_touch_point(uint16_t x, uint16_t y, uint16_t color)
{
atk_md0280_draw_line(x - 12, y, x + 13, y, color);
atk_md0280_draw_line(x, y - 12, x, y + 13, color);
atk_md0280_draw_point(x + 1, y + 1, color);
atk_md0280_draw_point(x - 1, y + 1, color);
atk_md0280_draw_point(x + 1, y - 1, color);
atk_md0280_draw_point(x - 1, y - 1, color);
atk_md0280_draw_circle(x, y, 6, color);
}
/**
* @brief ATK-MD0280模块触摸校准
* @param 无
* @retval 无
*/
static void atk_md0280_touch_calibration(void)
{
struct
{
uint16_t x;
uint16_t y;
} point[];
uint8_t point_index;
int16_t d1, d2, d3, d4;
double x_fac, y_fac;
atk_md0280_clear(ATK_MD0280_WHITE);
atk_md0280_show_string( 40,
40,
ATK_MD0280_LCD_WIDTH - 80,
ATK_MD0280_LCD_HEIGHT - 80,
"Please use the stylus click the cross on the screen.The cross will always move until the screen adjustment is completed.",
ATK_MD0280_LCD_FONT_16,
ATK_MD0280_RED);
while (1)
{
for (point_index=0; point_index<5 + 1; point_index++)
{
switch (point_index)
{
case 0:
{
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() >> 1, atk_md0280_get_lcd_height() >> 1, ATK_MD0280_WHITE);
atk_md0280_touch_draw_touch_point(20, 20, ATK_MD0280_RED);
break;
}
case 1:
{
atk_md0280_touch_draw_touch_point(20, 20, ATK_MD0280_WHITE);
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() - 20, 20, ATK_MD0280_RED);
break;
}
case 2:
{
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() - 20, 20, ATK_MD0280_WHITE);
atk_md0280_touch_draw_touch_point(20, atk_md0280_get_lcd_height() - 20, ATK_MD0280_RED);
break;
}
case 3:
{
atk_md0280_touch_draw_touch_point(20, atk_md0280_get_lcd_height() - 20, ATK_MD0280_WHITE);
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() - 20, atk_md0280_get_lcd_height() - 20, ATK_MD0280_RED);
break;
}
case 4:
{
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() - 20, atk_md0280_get_lcd_height() - 20, ATK_MD0280_WHITE);
atk_md0280_touch_draw_touch_point(atk_md0280_get_lcd_width() >> 1, atk_md0280_get_lcd_height() >> 1, ATK_MD0280_RED);
break;
}
case 5:
{
d1 = point[].x - point[].x;
d3 = point[].x - point[].x;
d2 = point[].y - point[].y;
d4 = point[].y - point[].y;
x_fac = (double)d1 / d3;
y_fac = (double)d2 / d4;
if (x_fac < 0)
{
x_fac = -x_fac;
}
if (y_fac < 0)
{
y_fac = -y_fac;
}
if ( x_fac < 0.95 || x_fac > 1.05 || y_fac < 0.95 || y_fac > 1.05 ||
abs(d1) > 4095 || abs(d2) > 4095 || abs(d3) > 4095 || abs(d4) > 4095 ||
abs(d1) == 0 || abs(d2) == 0 || abs(d3) == 0 || abs(d4) == 0)
{
break;
}
g_atk_md0280_touch_sta.fac.x = (float)(d1 + d3) / ((atk_md0280_get_lcd_width() - 40) << 1);
g_atk_md0280_touch_sta.fac.y = (float)(d2 + d4) / ((atk_md0280_get_lcd_height() - 40) << 1);
g_atk_md0280_touch_sta.center.x = point[].x;
g_atk_md0280_touch_sta.center.y = point[].y;
atk_md0280_clear(ATK_MD0280_WHITE);
atk_md0280_show_string( 30,
100,
atk_md0280_get_lcd_width(),
atk_md0280_get_lcd_height(),
"Touch Screen Adjust OK!",
ATK_MD0280_LCD_FONT_16,
ATK_MD0280_BLUE);
delay_ms(1000);
atk_md0280_clear(ATK_MD0280_WHITE);
return;
}
}
delay_ms(200);
while (ATK_MD0280_TOUCH_READ_PEN() != 0);
point[].x = atk_md0280_touch_get_adc2(ATK_MD0280_TOUCH_CMD_X);
point[].y = atk_md0280_touch_get_adc2(ATK_MD0280_TOUCH_CMD_Y);
while (ATK_MD0280_TOUCH_READ_PEN() == 0);
}
}
}
/**
* @brief ATK-MD0280模块触摸初始化
* @param 无
* @retval 无
*/
void atk_md0280_touch_init(void)
{
atk_md0280_touch_hw_init();
atk_md0280_touch_spi_init();
atk_md0280_touch_calibration();
}
/**
* @brief ATK-MD0280模块触摸扫描
* @param x: 扫描到触摸的X坐标
* y: 扫描到触摸的Y坐标
* @retval ATK_MD0280_TOUCH_EOK : 扫描到有效的触摸
* ATK_MD0280_TOUCH_ERROR: 触摸坐标无效
* ATK_MD0280_TOUCH_EMPTY: 未扫描到有效的触摸
*/
uint8_t atk_md0280_touch_scan(uint16_t *x, uint16_t *y)
{
uint16_t x_adc;
uint16_t y_adc;
atk_md0280_lcd_disp_dir_t dir;
uint16_t x_raw;
uint16_t y_raw;
if (ATK_MD0280_TOUCH_READ_PEN() == 0)
{
x_adc = atk_md0280_touch_get_adc2(ATK_MD0280_TOUCH_CMD_X);
y_adc = atk_md0280_touch_get_adc2(ATK_MD0280_TOUCH_CMD_Y);
x_raw = (int16_t)(x_adc - g_atk_md0280_touch_sta.center.x) / g_atk_md0280_touch_sta.fac.x + ATK_MD0280_LCD_WIDTH / 2;
y_raw = (int16_t)(y_adc - g_atk_md0280_touch_sta.center.y) / g_atk_md0280_touch_sta.fac.y + ATK_MD0280_LCD_HEIGHT / 2;
if((x_raw >= ATK_MD0280_LCD_WIDTH) || (y_raw >= ATK_MD0280_LCD_HEIGHT))
{
return ATK_MD0280_TOUCH_ERROR;
}
dir = atk_md0280_get_disp_dir();
switch (dir)
{
case ATK_MD0280_LCD_DISP_DIR_0:
{
*x = x_raw;
*y = y_raw;
break;
}
case ATK_MD0280_LCD_DISP_DIR_90:
{
*x = y_raw;
*y = atk_md0280_get_lcd_height() - x_raw;
break;
}
case ATK_MD0280_LCD_DISP_DIR_180:
{
*x = atk_md0280_get_lcd_width() - x_raw;
*y = atk_md0280_get_lcd_height() - y_raw;
break;
}
case ATK_MD0280_LCD_DISP_DIR_270:
{
*x = atk_md0280_get_lcd_width() - y_raw;
*y = x_raw;
break;
}
}
return ATK_MD0280_TOUCH_EOK;
}
return ATK_MD0280_TOUCH_EMPTY;
}
#endif /* ATK_MD0280_USING_TOUCH */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
atk_md0280_touch_spi.h
c
/**
****************************************************************************************************
* @file atk_md0280_touch_spi.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块触摸SPI接口驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#ifndef __ATK_MD0280_TOUCH_SPI_H
#define __ATK_MD0280_TOUCH_SPI_H
#include "atk_md0280.h"
#if (ATK_MD0280_USING_TOUCH != 0)
/* 引脚定义 */
#define ATK_MD0280_TOUCH_SPI_MI_GPIO_RCU RCU_GPIOB
#define ATK_MD0280_TOUCH_SPI_MI_GPIO_PORT GPIOB
#define ATK_MD0280_TOUCH_SPI_MI_GPIO_PIN GPIO_PIN_12
#define ATK_MD0280_TOUCH_SPI_MO_GPIO_RCU RCU_GPIOD
#define ATK_MD0280_TOUCH_SPI_MO_GPIO_PORT GPIOD
#define ATK_MD0280_TOUCH_SPI_MO_GPIO_PIN GPIO_PIN_8
#define ATK_MD0280_TOUCH_SPI_TCS_GPIO_RCU RCU_GPIOB
#define ATK_MD0280_TOUCH_SPI_TCS_GPIO_PORT GPIOB
#define ATK_MD0280_TOUCH_SPI_TCS_GPIO_PIN GPIO_PIN_14
#define ATK_MD0280_TOUCH_SPI_CLK_GPIO_RCU RCU_GPIOD
#define ATK_MD0280_TOUCH_SPI_CLK_GPIO_PORT GPIOD
#define ATK_MD0280_TOUCH_SPI_CLK_GPIO_PIN GPIO_PIN_10
/* IO操作 */
#define ATK_MD0280_TOUCH_SPI_READ_MI() gpio_input_bit_get(ATK_MD0280_TOUCH_SPI_MI_GPIO_PORT, ATK_MD0280_TOUCH_SPI_MI_GPIO_PIN)
#define ATK_MD0280_TOUCH_SPI_MO(x) gpio_bit_write(ATK_MD0280_TOUCH_SPI_MO_GPIO_PORT, ATK_MD0280_TOUCH_SPI_MO_GPIO_PIN, x)
#define ATK_MD0280_TOUCH_SPI_TCS(x) gpio_bit_write(ATK_MD0280_TOUCH_SPI_TCS_GPIO_PORT, ATK_MD0280_TOUCH_SPI_TCS_GPIO_PIN, x)
#define ATK_MD0280_TOUCH_SPI_CLK(x) gpio_bit_write(ATK_MD0280_TOUCH_SPI_CLK_GPIO_PORT, ATK_MD0280_TOUCH_SPI_CLK_GPIO_PIN, x)
/* 操作函数 */
void atk_md0280_touch_spi_init(void); /* ATK-MD0280模块触摸SPI接口初始化 */
uint16_t atk_md0280_touch_spi_read(uint8_t cmd); /* ATK-MD0280模块触摸SPI接口读数据 */
#endif /* ATK_MD0280_USING_TOUCH */
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
atk_md0280_touch_spi.c
c
/**
****************************************************************************************************
* @file atk_md0280_touch_spi.c
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块触摸SPI接口驱动代码
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#include "atk_md0280_touch_spi.h"
#include "board.h"
#if (ATK_MD0280_USING_TOUCH != 0)
/**
* @brief ATK-MD0280模块触摸SPI接口写数据
* @param 待写入的数据
* @retval 无
*/
static void atk_md0280_touch_spi_write(uint8_t dat)
{
uint8_t dat_index;
for (dat_index=0; dat_index<8; dat_index++)
{
if ((dat & 0x80) != 0)
{
ATK_MD0280_TOUCH_SPI_MO(1);
}
else
{
ATK_MD0280_TOUCH_SPI_MO(0);
}
dat <<= 1;
ATK_MD0280_TOUCH_SPI_CLK(0);
delay_us(1);
ATK_MD0280_TOUCH_SPI_CLK(1);
}
}
/**
* @brief ATK-MD0280模块触摸SPI接口初始化
* @param 无
* @retval 无
*/
void atk_md0280_touch_spi_init(void)
{
/* 使能时钟 */
rcu_periph_clock_enable(ATK_MD0280_TOUCH_SPI_MI_GPIO_RCU);
rcu_periph_clock_enable(ATK_MD0280_TOUCH_SPI_MO_GPIO_RCU);
rcu_periph_clock_enable(ATK_MD0280_TOUCH_SPI_TCS_GPIO_RCU);
rcu_periph_clock_enable(ATK_MD0280_TOUCH_SPI_CLK_GPIO_RCU);
/* 初始化MI引脚 */
gpio_mode_set(ATK_MD0280_TOUCH_SPI_MI_GPIO_PORT,GPIO_MODE_INPUT,GPIO_PUPD_NONE,ATK_MD0280_TOUCH_SPI_MI_GPIO_PIN);
/* 初始化MO引脚 */
gpio_mode_set(ATK_MD0280_TOUCH_SPI_MO_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_TOUCH_SPI_MO_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_TOUCH_SPI_MO_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_TOUCH_SPI_MO_GPIO_PIN);
/* 初始化TCS引脚 */
gpio_mode_set(ATK_MD0280_TOUCH_SPI_TCS_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_TOUCH_SPI_TCS_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_TOUCH_SPI_TCS_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_TOUCH_SPI_TCS_GPIO_PIN);
/* 初始化CLK引脚 */
gpio_mode_set(ATK_MD0280_TOUCH_SPI_CLK_GPIO_PORT,GPIO_MODE_OUTPUT,GPIO_PUPD_PULLUP,ATK_MD0280_TOUCH_SPI_CLK_GPIO_PIN);
gpio_output_options_set(ATK_MD0280_TOUCH_SPI_CLK_GPIO_PORT,GPIO_OTYPE_PP,GPIO_OSPEED_50MHZ,ATK_MD0280_TOUCH_SPI_CLK_GPIO_PIN);
}
/**
* @brief ATK-MD0280模块触摸SPI接口读数据
* @param 无
* @retval 读出的数据
*/
uint16_t atk_md0280_touch_spi_read(uint8_t cmd)
{
uint16_t dat = 0;
uint8_t dat_index;
ATK_MD0280_TOUCH_SPI_CLK(0);
ATK_MD0280_TOUCH_SPI_MO(0);
ATK_MD0280_TOUCH_SPI_TCS(0);
atk_md0280_touch_spi_write(cmd);
delay_us(6);
ATK_MD0280_TOUCH_SPI_CLK(0);
delay_us(1);
ATK_MD0280_TOUCH_SPI_CLK(1);
delay_us(1);
ATK_MD0280_TOUCH_SPI_CLK(0);
for (dat_index=0; dat_index<16; dat_index++)
{
dat <<= 1;
ATK_MD0280_TOUCH_SPI_CLK(0);
delay_us(1);
ATK_MD0280_TOUCH_SPI_CLK(1);
if (ATK_MD0280_TOUCH_SPI_READ_MI() != 0)
{
dat++;
}
}
dat >>= 4;
ATK_MD0280_TOUCH_SPI_TCS(1);
return dat;
}
#endif /* ATK_MD0280_USING_TOUCH */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
demo.c
c
/**
****************************************************************************************************
* @file demo.c
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块测试实验(GPIO)
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#include "demo.h"
#include "atk_md0280.h"
#include "board.h"
#include <math.h>
#define PI (float)(3.1415926)
static float cube[][] = {
{-16, -16, -16},
{-16, +16, -16},
{+16, +16, -16},
{+16, -16, -16},
{-16, -16, +16},
{-16, +16, +16},
{+16, +16, +16},
{+16, -16, +16}
};
static uint8_t line_id[] = {
1, 2, 2, 3,
3, 4, 4, 1,
5, 6, 6, 7,
7, 8, 8, 5,
8, 4, 7, 3,
6, 2, 5, 1
};
/**
* @brief 计算矩阵乘法
* @param a : 矩阵a
* b[][]: 矩阵b
* @retval 计算结果
*/
static float *demo_matconv(float *a, float b[][])
{
float res[];
uint8_t res_index;
uint8_t a_index;
for (res_index=0; res_index<3; res_index++)
{
res[] = b[][] * a[] + b[][] * a[] + b[][] * a[];
}
for (a_index=0; a_index<3; a_index++)
{
a[] = res[];
}
return a;
}
/**
* @brief 旋转向量
* @param point: 需要旋转的向量
* x : X轴旋转量
* y : Y轴旋转量
* z : Z轴旋转量
* @retval 计算结果
*/
static void demo_rotate(float *point, float x, float y, float z)
{
float rx[][];
float ry[][];
float rz[][];
x /= PI;
y /= PI;
z /= PI;
rx[][] = cos(x);
rx[][] = 0;
rx[][] = sin(x);
rx[][] = 0;
rx[][] = 1;
rx[][] = 0;
rx[][] = -sin(x);
rx[][] = 0;
rx[][] = cos(x);
ry[][] = 1;
ry[][] = 0;
ry[][] = 0;
ry[][] = 0;
ry[][] = cos(y);
ry[][] = -sin(y);
ry[][] = 0;
ry[][] = sin(y);
ry[][] = cos(y);
rz[][] = cos(z);
rz[][] = -sin(z);
rz[][] = 0;
rz[][] = sin(z);
rz[][] = cos(z);
rz[][] = 0;
rz[][] = 0;
rz[][] = 0;
rz[][] = 1;
demo_matconv(demo_matconv(demo_matconv(point, rz), ry), rx);
}
/**
* @brief 演示立方体3D旋转
* @param 无
* @retval 无
*/
static void demo_show_cube(void)
{
uint8_t point_index;
uint8_t line_index;
static uint16_t x = 120;
static uint16_t y = 201;
uint16_t x_scan;
uint16_t y_scan;
/* ATK-MD0280模块触摸扫描 */
if (atk_md0280_touch_scan(&x_scan, &y_scan) == 0)
{
if ((x_scan > 28) && (x_scan < (atk_md0280_get_lcd_width() - 28)) && (y_scan > 110) && (y_scan < (atk_md0280_get_lcd_height() - 28)))
{
x = x_scan;
y = y_scan;
}
}
for (point_index=0; point_index<8; point_index++)
{
demo_rotate(cube[], 0.5f, 0.3f, 0.2f);
}
for (line_index=0; line_index<24; line_index+=2)
{
/* ATK-MD0280模块LCD画线段 */
atk_md0280_draw_line( x + cube[] - 1][],
y + cube[] - 1][],
x + cube[] - 1][],
y + cube[] - 1][],
ATK_MD0280_BLUE);
}
delay_ms(100);
atk_md0280_fill(x - 28, y - 28, x + 28, y + 28, ATK_MD0280_WHITE);
}
/**
* @brief 例程演示入口函数
* @param 无
* @retval 无
*/
void demo_run(void)
{
uint8_t ret;
/* 初始化ATK-MD0280模块 */
ret = atk_md0280_init();
if (ret != 0)
{
printf("ATK-MD0280 init failed!\r\n");
while (1)
{
printf("atk_md0280_init Error!!!\r\n");
delay_ms(200);
}
}
printf("Demo--->Atk_Md0280_init Succeed!!!\r\n");
/* ATK-MD0280模块LCD清屏 */
atk_md0280_clear(ATK_MD0280_WHITE);
/* ATK-MD0280模块LCD显示字符串 */
atk_md0280_show_string(10, 10, ATK_MD0280_LCD_WIDTH, 32, "STM32", ATK_MD0280_LCD_FONT_32, ATK_MD0280_RED);
atk_md0280_show_string(10, 42, ATK_MD0280_LCD_WIDTH, 24, "ATK-MD0280", ATK_MD0280_LCD_FONT_24, ATK_MD0280_RED);
atk_md0280_show_string(10, 66, ATK_MD0280_LCD_WIDTH, 16, "ATOM@ALIENTEK", ATK_MD0280_LCD_FONT_16, ATK_MD0280_RED);
while (1)
{
/* 演示立方体3D旋转 */
demo_show_cube();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
demo.h
c
/**
****************************************************************************************************
* @file demo.h
* @author 正点原子团队(ALIENTEK)
* @version V1.0
* @date 2022-06-21
* @brief ATK-MD0280模块测试实验(GPIO)
* @license Copyright (c) 2020-2032, 广州市星翼电子科技有限公司
****************************************************************************************************
* @attention
*
* 实验平台:正点原子 MiniSTM32 V4开发板
* 在线视频:www.yuanzige.com
* 技术论坛:www.openedv.com
* 公司网址:www.alientek.com
* 购买地址:openedv.taobao.com
*
****************************************************************************************************
*/
#ifndef __DEMO_H
#define __DEMO_H
void demo_run(void);
#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
将atk_md0280_font.h中的头文件语句更改一下:
移植验证
在main.c中输入代码如下
c
#include "board.h"
#include "demo.h"
int main(void)
{
board_init();
bsp_uart_init();
demo_run(); /* 运行示例程序 */
while(1)
{
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
上电效果:
移植成功案例:
代码下载
链接在开发板介绍
章节的资料下载!!