Articles
4
Home
文本处理工具
代码生成器
bes
Arduino
python
freertos
zklx
C#
xilinx
3D打印实用工具
Archives
找到我
Fun
Home
文本处理工具
代码生成器
bes
Arduino
python
freertos
zklx
C#
xilinx
3D打印实用工具
Archives
找到我
Fun
复制粘贴工程师专用工具
GPIO初始化
#define XX_GPIO_PIN HAL_GPIO_PIN_P0_3 #define XX_IOMUX_PIN HAL_IOMUX_PIN_P0_3 const struct HAL_IOMUX_PIN_FUNCTION_MAP xx_io_cfg[1] = { {XX_IOMUX_PIN, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENALBE}, }; void xx_gpio_init(void) { hal_iomux_init(xx_io_cfg, 1); hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T) xx_io_cfg[0].pin, HAL_GPIO_DIR_IN, 1); // uart_gpiokey_enable_irq(RX_GPIO_PIN, HAL_GPIO_IRQ_POLARITY_LOW_FALLING); } bool xx_gpio_read(void) { hal_iomux_init(xx_io_cfg, 1); hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T) xx_io_cfg[0].pin, HAL_GPIO_DIR_IN, 1); return hal_gpio_pin_get_val(XX_GPIO_PIN); } void xx_gpio_write(bool b) { hal_iomux_init(xx_io_cfg, 1); hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T) xx_io_cfg[0].pin, HAL_GPIO_DIR_OUT, 1); if(b) hal_gpio_pin_set(XX_GPIO_PIN); else hal_gpio_pin_clr(XX_GPIO_PIN); }
GPIO中断
#define XX_GPIO_PIN HAL_GPIO_PIN_P0_2 #define XX_IOMUX_PIN HAL_IOMUX_PIN_P0_2 const struct HAL_IOMUX_PIN_FUNCTION_MAP xx_io_cfg[1] = { {XX_IOMUX_PIN, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}, }; void xx_irqhandler(enum HAL_GPIO_PIN_T pin); static void hal_gpiokey_enable_irq(enum HAL_GPIO_PIN_T pin, enum HAL_GPIO_IRQ_POLARITY_T polarity) { struct HAL_GPIO_IRQ_CFG_T gpiocfg; hal_gpio_pin_set_dir(pin, HAL_GPIO_DIR_IN, 0); gpiocfg.irq_enable = true; gpiocfg.irq_debounce = true; gpiocfg.irq_polarity = polarity; gpiocfg.irq_handler = xx_irqhandler; gpiocfg.irq_type = HAL_GPIO_IRQ_TYPE_LEVEL_SENSITIVE; hal_gpio_setup_irq(pin, &gpiocfg); } void xx_enable_irq(void) { hal_iomux_init(xx_io_cfg, 1); hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T) xx_io_cfg[0].pin, HAL_GPIO_DIR_IN, 1); hal_gpiokey_enable_irq(XX_GPIO_PIN, HAL_GPIO_IRQ_POLARITY_LOW_FALLING); } void xx_irqhandler(enum HAL_GPIO_PIN_T pin) { TRACE(0," hal irq"); //hal_gpiokey_disable_irq(XX_GPIO_PIN); /* APP_MESSAGE_BLOCK msg; msg.mod_id = APP_MODUAL_XX; msg.msg_body.message_id = XX_EINT_EVT; msg.msg_body.message_ptr = (uint32_t) NULL; app_mailbox_put(&msg); */ }
mail
void xx_msg2boxprocess(uint8_t evt) { APP_MESSAGE_BLOCK msg; msg.mod_id = APP_MODUAL_XX; msg.msg_body.message_id = evt; msg.msg_body.message_ptr = (uint32_t) NULL; app_mailbox_put(&msg); } int xx_process(APP_MESSAGE_BODY * msg) { switch (msg->message_id) { case FEED_DOG_EVT: //your code break; } return 0; } int xx_process_init(void) { app_set_threadhandle(APP_MODUAL_XX, xx_process); }
timer
void xx_timerhandler(void const * param); osTimerDef(XX_TIMER, xx_timerhandler); osTimerId xx_timer = NULL; #define XX_TIME_MS 1000 void xx_timerhandler(void const * param) { TRACE("xx_timehandler"); //your code } void xx_timer_start(void) { TRACE("xx_timer_start"); if (xx_timer == NULL) { xx_timer = osTimerCreate(osTimer(XX_TIMER), osTimerPeriodic, NULL); xx_timer = osTimerCreate(osTimer(XX_TIMER), osTimerOnce, NULL); osTimerStop(xx_timer); } osTimerStart(xx_timer,XX_TIME_MS); } void xx_timer_stop(void) { TRACE("xx_timer_stop"); if (xx_timer != NULL) { osTimerStop(xx_timer); } }
nv
void nv_write_xx_flag(bool val) { struct nvrecord_env_t *nvrecord_env; nv_record_env_get(&nvrecord_env); if(nvrecord_env->xx_flag!=val) { nvrecord_env->xx_flag=val; nv_record_env_set(nvrecord_env); TRACE("nv_write_xx_flag %d",val); nv_record_flash_flush(); } else return; } bool nv_read_xx_flag(void) { struct nvrecord_env_t *nvrecord_env; nv_record_env_get(&nvrecord_env); TRACE("nv_read_xx_flag %d",nvrecord_env->xx_flag); return (nvrecord_env->xx_flag); }
i2c
#define ADDR 0x01 uint32_t xx_open(void) { static const struct HAL_GPIO_I2C_CONFIG_T i2c_cfg= {HAL_GPIO_PIN_P2_0,HAL_GPIO_PIN_P2_1,10}; hal_gpio_i2c_open(&i2c_cfg); //add sensor init code //... return 0; } /* i2c write */ static int I2C_WriteByte(uint8_t reg_addr, uint8_t value) { uint8_t buf[2]; buf[0] = reg_addr; buf[1] = value; uint32_t ret=0; ret= hal_gpio_i2c_simple_send(ADDR,buf,2); TRACE("hal_gpio_i2c_simple_send ret=%d ",ret); return ret; } static int I2C_WriteWord(uint8_t reg_addr, uint16_t value) { uint8_t buf[3]; buf[0] = reg_addr; buf[1] = (uint8_t)(value&0xff); buf[2] = (uint8_t)(value>>8); uint32_t ret=0; ret= hal_gpio_i2c_simple_send(ADDR,buf,3); TRACE("hal_gpio_i2c_simple_send ret=%d ",ret); return ret; } static int I2C_ReadByte(uint8_t reg_addr, uint8_t *value) { //uint8_t buf[2]={0,0}; uint32_t ret=0; ret= hal_gpio_i2c_simple_recv(ADDR,®_addr,1,value,1); TRACE("hal_gpio_i2c_simple_send ret=%d ",ret); return ret; } static int I2C_ReadWord(uint8_t reg_addr, uint16_t *value) { uint8_t buf[2]= {0,0}; uint32_t ret=0; ret= hal_gpio_i2c_simple_recv(ADDR,®_addr,1,buf,2); TRACE("hal_gpio_i2c_simple_send ret=%d ",ret); *value=(uint16_t)buf[0]|(uint16_t)buf[1]<<8; return ret; }
zhoushenglin
Articles
4
Bookmark
Announcement
Hello!
Recent Post
WSL下安装petalinux
2022-08-19
video
2020-08-14
关于这个网站
2020-08-10
更新记录
2020-08-10
Archives
August 2022
1
August 2020
3
Info
Article :
4
UV :
PV :
2