282 lines
7.2 KiB
C
282 lines
7.2 KiB
C
#include "main.h"
|
|
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
#include "../lvgl/lvgl.h"
|
|
#include "../ili9341/core.h"
|
|
#include "../ili9341/lv_driver.h"
|
|
#include "lv_conf.h"
|
|
|
|
short gPosx,gPosy;
|
|
lv_indev_t * indev_touchpad; // ?????????
|
|
lv_obj_t* kb;
|
|
|
|
short ReadX(){
|
|
static short average[2] = {0};
|
|
static unsigned char pos = 0;
|
|
short ret = 0;
|
|
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
|
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_1);
|
|
|
|
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_1);
|
|
LL_mDelay(1);
|
|
ADC1->CHSELR = LL_ADC_CHANNEL_8;
|
|
ADC1->IER = 0;
|
|
ADC1->CR |= ADC_CR_ADSTART;
|
|
|
|
while (ADC1->CR & ADC_CR_ADSTART)
|
|
;
|
|
|
|
if( LL_ADC_REG_ReadConversionData32(ADC1) < 500){
|
|
gPosy = -1;
|
|
return -1;
|
|
}
|
|
float s = (float)( LL_ADC_REG_ReadConversionData32(ADC1) -600)/11.65;
|
|
ret = s;
|
|
{
|
|
gPosy = ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
short ReadY(){
|
|
static short average[3] = {0};
|
|
static unsigned char pos = 0;
|
|
short ret = 0;
|
|
|
|
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
|
|
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
|
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
|
|
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_0);
|
|
|
|
LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_0);
|
|
LL_mDelay(1);
|
|
ADC1->CHSELR = LL_ADC_CHANNEL_9;
|
|
ADC1->IER = 0;
|
|
ADC1->CR |= ADC_CR_ADSTART;
|
|
|
|
while (ADC1->CR & ADC_CR_ADSTART)
|
|
;
|
|
|
|
ret = LL_ADC_REG_ReadConversionData32(ADC1);
|
|
if(ret < 500) {
|
|
gPosx = -1;
|
|
return -1;
|
|
}
|
|
float tmp = (float)(3560 - ret)/9.3;
|
|
ret = (short)tmp;
|
|
if(ret < 0)
|
|
return 0;
|
|
else {
|
|
gPosx = ret;
|
|
return ret;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
static bool touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
|
|
{
|
|
static lv_coord_t last_x = 0;
|
|
static lv_coord_t last_y = 0;
|
|
|
|
|
|
if( (gPosy > 0 )&&(gPosx > 0)) {
|
|
last_x = gPosx;
|
|
last_y = gPosy;
|
|
|
|
data->point.x = last_x;
|
|
data->point.y = last_y;
|
|
data->state = LV_INDEV_STATE_PR;
|
|
}
|
|
else
|
|
{
|
|
data->point.x = last_x;
|
|
data->point.y = last_y;
|
|
data->state = LV_INDEV_STATE_REL;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static void ta_event_cb(lv_event_t * e)
|
|
{
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
lv_obj_t * ta = lv_event_get_target(e);
|
|
lv_obj_t * kb = lv_event_get_user_data(e);
|
|
if(code == LV_EVENT_FOCUSED) {
|
|
lv_keyboard_set_textarea(kb, ta);
|
|
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
|
}
|
|
if(code == LV_EVENT_DEFOCUSED) {
|
|
lv_keyboard_set_textarea(kb, NULL);
|
|
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
|
}
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
char tmp[20] = "x: ";
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/* MCU Configuration--------------------------------------------------------*/
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG);
|
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
|
|
|
/* SysTick_IRQn interrupt configuration */
|
|
NVIC_SetPriority(SysTick_IRQn, 3);
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* Configure the system clock */
|
|
SystemClock_Config();
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
|
|
/* USER CODE END SysInit */
|
|
|
|
/* Initialize all configured peripherals */
|
|
MX_GPIO_Init();
|
|
MX_DMA_Init();
|
|
MX_SPI2_Init();
|
|
MX_ADC_Init();
|
|
LL_mDelay(100);
|
|
LL_ADC_Enable(ADC1);
|
|
|
|
|
|
lv_init(); // LittleVgl (6.0)
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
ILI9341_init();
|
|
|
|
/* USER CODE END 2 */
|
|
LL_mDelay(100);
|
|
|
|
static lv_color_t disp_buf1[320 * 10] = {0};
|
|
static lv_disp_draw_buf_t buf;
|
|
lv_disp_draw_buf_init(&buf, disp_buf1, NULL, 320 * 10);
|
|
|
|
|
|
lv_disp_drv_t disp_drv;
|
|
lv_disp_drv_init(&disp_drv);
|
|
disp_drv.draw_buf = &buf;
|
|
disp_drv.flush_cb = ILI9341_flush;
|
|
disp_drv.hor_res = 320; /*Set the horizontal resolution in pixels*/
|
|
disp_drv.ver_res = 240; /*Set the vertical resolution in pixels*/
|
|
lv_disp_drv_register(&disp_drv);
|
|
LL_mDelay(100);
|
|
|
|
|
|
lv_indev_drv_t indev_drv;
|
|
|
|
lv_indev_drv_init(&indev_drv);
|
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
|
indev_drv.read_cb = touchpad_read;
|
|
indev_touchpad = lv_indev_drv_register(&indev_drv);
|
|
|
|
lv_obj_t *src = lv_scr_act();
|
|
|
|
lv_obj_t *label1 = lv_label_create(src);
|
|
lv_obj_t *label2 = lv_label_create(src);
|
|
|
|
//LV_LABEL_LONG_EXPAND
|
|
lv_obj_set_pos(label1,120,20);
|
|
lv_obj_set_size(label1,100,50);
|
|
sprintf(tmp,"x:%d", ReadX());
|
|
lv_label_set_text(label1,tmp);
|
|
//lv_obj_set_style_bg_color(lv_scr_act(), lv_palette_lighten(LV_PALETTE_GREY, 4), 0);
|
|
|
|
lv_obj_set_pos(label2,120,50);
|
|
lv_obj_set_size(label2,100,50);
|
|
sprintf(tmp,"y:%d", ReadY());
|
|
lv_label_set_text(label2,tmp);
|
|
|
|
lv_obj_t *label = lv_label_create(lv_scr_act());
|
|
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x000000), 0); //0x000000 = ??
|
|
lv_label_set_recolor(label, true); //??????
|
|
lv_obj_set_pos(label, 10, 10); //????
|
|
lv_obj_set_size(label, 80, 60); //?????
|
|
LV_FONT_DECLARE(lv_font_montserrat_20) //????
|
|
lv_label_set_text(label, "#00ff80 freq:#"); //????
|
|
lv_obj_set_style_text_font(label, &lv_font_montserrat_20, 0);
|
|
|
|
kb = lv_keyboard_create(lv_scr_act());
|
|
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
|
|
lv_obj_t * ta;
|
|
ta = lv_textarea_create(lv_scr_act());
|
|
lv_obj_add_event_cb(ta, ta_event_cb, LV_EVENT_ALL, kb);
|
|
lv_obj_set_pos(ta, 90, 10); //????
|
|
lv_textarea_set_placeholder_text(ta, "10000000");
|
|
lv_obj_set_size(ta, 200, 60);
|
|
static lv_style_t style;
|
|
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
while (1)
|
|
{
|
|
LL_mDelay(1);
|
|
/* USER CODE END WHILE */
|
|
lv_task_handler();
|
|
lv_tick_inc(10);
|
|
ReadX();
|
|
ReadY();
|
|
|
|
//sprintf(tmp,"y:%d", ReadX());
|
|
//lv_label_set_text(label1,tmp);//??????
|
|
//LL_mDelay(1);
|
|
//sprintf(tmp,"x:%d", ReadY());
|
|
//lv_label_set_text(label2,tmp);//??????
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
}
|
|
/* USER CODE END 3 */
|
|
}
|