初学杰理有很多资料不全,所以,我把杰理ac632n的板级文件做了阅读和批注。
首先,该板级文件有三个,分别是
我们首先需要关注board_ac632n_demo.c,这里面主要有关于power和key以及gpio的配置。
首先需要关注的是按键配置。
/************************** IO KEY ****************************/
#if TCFG_IOKEY_ENABLE
const struct iokey_port iokey_list[] = {
{
.connect_way = TCFG_IOKEY_POWER_CONNECT_WAY, //IO按键的连接方式
.key_type.one_io.port = TCFG_IOKEY_POWER_ONE_PORT, //IO按键对应的引脚
.key_value = 0, //按键值
},
{
.connect_way = TCFG_IOKEY_PREV_CONNECT_WAY,
.key_type.one_io.port = TCFG_IOKEY_PREV_ONE_PORT,
.key_value = 1,
},
// {
// .connect_way = TCFG_IOKEY_NEXT_CONNECT_WAY,
// .key_type.one_io.port = TCFG_IOKEY_NEXT_ONE_PORT,
// .key_value = 2,
// },
};
const struct iokey_platform_data iokey_data = {
.enable = TCFG_IOKEY_ENABLE, //是否使能IO按键
.num = ARRAY_SIZE(iokey_list), //IO按键的个数
.port = iokey_list, //IO按键参数表
};
在此处要记得使能,且要在.h文件里修改。修改结束后需要在codeblocks里检查一下(codeblocks里的头文件有时候无法保存修改,这个问题之后再去解决)。
该处可以修改gpio关机后的状态,如果想在关机后用gpio唤醒(比如充电唤醒),可以在此处加io口保护,其中保护的代码最好放在该函数的下面。
static void close_gpio(u8 is_softoff)
{
u16 port_group[] = {
[PORTA_GROUP] = 0x1ff,
[PORTB_GROUP] = 0x3ff,//
[PORTC_GROUP] = 0x3ff,//
};
if(P3_ANA_CON2 & BIT(3))
{
port_protect(port_group, IO_PORTB_02); //protect VCM_IO
}
if(P3_PINR_CON & BIT(0))
{
u8 port_sel = P3_PORT_SEL0;
if((port_sel >= 1) && (port_sel <= 10)){
port_sel = IO_GROUP_NUM * 0 + port_sel - 1;
port_protect(port_group, port_sel); //protect 长按复位
}else if((port_sel >= 11) && (port_sel <= 20)){
port_sel = IO_GROUP_NUM * 1 + port_sel - 11;
port_protect(port_group, port_sel); //protect 长按复位
}else if((port_sel >= 21) && (port_sel <= 25)){
port_sel = IO_GROUP_NUM * 2 + port_sel - 21;
port_protect(port_group, port_sel); //protect 长按复位
}else if(port_sel == 26){
port_protect(port_group, IO_PORT_DP); //protect 长按复位
}else if(port_sel == 27){
port_protect(port_group, IO_PORT_DM); //protect 长按复位
}else if(port_sel == 28){
port_protect(port_group, IO_PORT_DP1); //protect 长按复位
}else if(port_sel == 29){
port_protect(port_group, IO_PORT_DM1); //protect 长按复位
}
}
#if TCFG_ADKEY_ENABLE
port_protect(port_group,TCFG_ADKEY_PORT);
#endif /* */
#if TCFG_IOKEY_ENABLE
port_protect(port_group, TCFG_IOKEY_POWER_ONE_PORT);
port_protect(port_group, TCFG_IOKEY_PREV_ONE_PORT);
// port_protect(port_group, TCFG_IOKEY_NEXT_ONE_PORT);
#endif /* TCFG_IOKEY_ENABLE */
#if TCFG_RTC_ALARM_ENABLE
/* port_protect(port_group, IO_PORTA_01); */
/* port_protect(port_group, IO_PORTA_02); */
#endif /* TCFG_RTC_ALARM_ENABLE */
#if TCFG_CHARGE_ENABLE && TCFG_HANDSHAKE_ENABLE
if (is_softoff == 0) {
port_protect(port_group, TCFG_HANDSHAKE_IO_DATA1);
port_protect(port_group, TCFG_HANDSHAKE_IO_DATA2);
}
#endif
#if CONFIG_APP_AT_CHAR_COM || CONFIG_APP_AT_COM
port_protect(port_group, UART_DB_TX_PIN);
port_protect(port_group, UART_DB_RX_PIN);
#if FLOW_CONTROL
port_protect(port_group, UART_DB_RTS_PIN);
port_protect(port_group, UART_DB_CTS_PIN);
#endif
#endif
//< close gpio
gpio_dir(GPIOA, 0, 9, port_group[PORTA_GROUP], GPIO_OR);
gpio_set_pu(GPIOA, 0, 9, ~port_group[PORTA_GROUP], GPIO_AND);
gpio_set_pd(GPIOA, 0, 9, ~port_group[PORTA_GROUP], GPIO_AND);
gpio_die(GPIOA, 0, 9, ~port_group[PORTA_GROUP], GPIO_AND);
gpio_dieh(GPIOA, 0, 9, ~port_group[PORTA_GROUP], GPIO_AND);
gpio_dir(GPIOB, 0, 10, port_group[PORTB_GROUP], GPIO_OR);
gpio_set_pu(GPIOB, 0, 10, ~port_group[PORTB_GROUP], GPIO_AND);
gpio_set_pd(GPIOB, 0, 10, ~port_group[PORTB_GROUP], GPIO_AND);
gpio_die(GPIOB, 0, 10, ~port_group[PORTB_GROUP], GPIO_AND);
gpio_dieh(GPIOB, 0, 10, ~port_group[PORTB_GROUP], GPIO_AND);
//< close usb io
/* usb0是烧录口 */
// usb_iomode(1);
// gpio_set_pull_up(IO_PORT_DP, 0);
// gpio_set_pull_down(IO_PORT_DP, 0);
// gpio_set_direction(IO_PORT_DP, 1);
// gpio_set_die(IO_PORT_DP, 0);
// gpio_set_dieh(IO_PORT_DP, 0);
// gpio_set_pull_up(IO_PORT_DM, 0);
// gpio_set_pull_down(IO_PORT_DM, 0);
// gpio_set_direction(IO_PORT_DM, 1);
// gpio_set_die(IO_PORT_DM, 0);
// gpio_set_dieh(IO_PORT_DM, 0);
usb1_iomode(1);
gpio_set_pull_up(IO_PORT_DP1, 0);
gpio_set_pull_down(IO_PORT_DP1, 0);
gpio_set_direction(IO_PORT_DP1, 1);
gpio_set_die(IO_PORT_DP1, 0);
gpio_set_dieh(IO_PORT_DP1, 0);
gpio_set_pull_up(IO_PORT_DM1, 0);
gpio_set_pull_down(IO_PORT_DM1, 0);
gpio_set_direction(IO_PORT_DM1, 1);
gpio_set_die(IO_PORT_DM1, 0);
gpio_set_dieh(IO_PORT_DM1, 0);
/* printf("JL_USB_IO->CON0=0x%x\r\n", JL_USB_IO->CON0); */
/* printf("JL_USB_IO->CON1=0x%x\r\n", JL_USB_IO->CON1); */
/* printf("JL_USB->CON0=0x%x\r\n", JL_USB->CON0); */
/* */
/* printf("JL_USB1_IO->CON0=0x%x\r\n", JL_USB1_IO->CON0); */
/* printf("JL_USB1_IO->CON1=0x%x\r\n", JL_USB1_IO->CON1); */
/* printf("JL_USB1->CON0=0x%x\r\n", JL_USB1->CON0); */
}
两个定时函数区别:
sys_timer_add(NULL, spple_timer_handle_test, 1000)
usr_timer_add(NULL, spple_timer_handle_test, 1000, 1)
网上说上面那个定时器只能跑10ms,但我用led灯测了之后觉得应该比10ms快。
使用sys_timer_add不用考虑优先级问题,usr_timer_add则有优先级问题。此外系统时钟可以在低功耗时使用(目前还不知道怎么进入低功耗模式)
c++如何调用c语言:
在头文件中做如下说明:
#ifndef __DEV_APP_H__
#define __DEV_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
void touch_detect_timer(void);
#ifdef __cplusplus
}
#endif
#endif
如果没有定义c++则会执行这些
#ifndef __DEV_APP_H__
#define __DEV_APP_H__
// #ifdef __cplusplus
// extern "C" {
// #endif
void touch_detect_timer(void);
// #ifdef __cplusplus
// }
// #endif
#endif
可以说完美的涵盖了c和c++的库。