2022-03-22 02:14:05 -07:00
|
|
|
/*
|
2022-05-12 00:32:34 -07:00
|
|
|
Copyright (C) 2022 Westberry Technology (ChangZhou) Corp., Ltd
|
2022-03-22 02:14:05 -07:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
2022-05-12 00:32:34 -07:00
|
|
|
#include "board.h"
|
2022-03-22 02:14:05 -07:00
|
|
|
|
2022-05-12 00:32:34 -07:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Private variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Generic code. */
|
|
|
|
/*===========================================================================*/
|
2022-03-22 02:14:05 -07:00
|
|
|
|
2022-05-12 00:32:34 -07:00
|
|
|
#define PORTAB_LINE_LED1 PAL_LINE(GPIOB, 14U)
|
|
|
|
#define PORTAB_LINE_LED2 PAL_LINE(GPIOB, 13U)
|
|
|
|
#define PORTAB_LED_OFF PAL_HIGH
|
|
|
|
#define PORTAB_LED_ON AL_LOW
|
2022-03-22 02:14:05 -07:00
|
|
|
|
2022-05-12 00:32:34 -07:00
|
|
|
#define PORTAB_LINE_BUTTON PAL_LINE(GPIOA, 0U)
|
|
|
|
#define PORTAB_BUTTON_PRESSED PAL_LOW
|
2022-05-12 00:17:06 -07:00
|
|
|
|
2022-05-12 00:32:34 -07:00
|
|
|
#if defined(PORTAB_LINE_LED2)
|
2022-05-12 00:17:06 -07:00
|
|
|
/*
|
2022-05-12 00:32:34 -07:00
|
|
|
* LED blinker thread, times are in milliseconds.
|
2022-05-12 00:17:06 -07:00
|
|
|
*/
|
|
|
|
static THD_WORKING_AREA(waThread1, 128);
|
2022-05-12 00:32:34 -07:00
|
|
|
static THD_FUNCTION(Thread1, arg)
|
|
|
|
{
|
2022-05-12 00:17:06 -07:00
|
|
|
(void)arg;
|
|
|
|
chRegSetThreadName("blinker");
|
2022-05-12 00:32:34 -07:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED ? 250 : 500;
|
|
|
|
palToggleLine(PORTAB_LINE_LED2);
|
|
|
|
chThdSleepMilliseconds(time);
|
2022-05-12 00:17:06 -07:00
|
|
|
}
|
2022-03-22 02:14:05 -07:00
|
|
|
}
|
2022-05-12 00:32:34 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PAL_USE_WAIT || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure PORTAB_LINE_BUTTON in interrupt mode
|
|
|
|
* @param None
|
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void EXTI0_Config(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Init button port and pad.
|
|
|
|
*/
|
|
|
|
palSetPadMode(PAL_PORT(PORTAB_LINE_BUTTON), PAL_PAD(PORTAB_LINE_BUTTON), PAL_WB32_MODE_INPUT | PAL_WB32_PUPDR_PULLDOWN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enabling events on both edges of the button line.
|
|
|
|
*/
|
|
|
|
palEnableLineEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_RISING_EDGE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the interrupt priority.
|
|
|
|
*/
|
|
|
|
nvicEnableVector(EXTI0_IRQn, WB32_IRQ_EXTI0_PRIORITY);
|
|
|
|
}
|
2022-03-22 02:14:05 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Application entry point.
|
|
|
|
*/
|
2022-05-12 00:32:34 -07:00
|
|
|
int main(void)
|
|
|
|
{
|
2022-03-22 02:14:05 -07:00
|
|
|
/*
|
|
|
|
* System initializations.
|
|
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
|
|
* and performs the board-specific initializations.
|
|
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
|
|
* RTOS is active.
|
|
|
|
*/
|
|
|
|
halInit();
|
|
|
|
chSysInit();
|
2022-05-12 00:32:34 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Init LED port and pad.
|
|
|
|
*/
|
|
|
|
palSetPadMode(PAL_PORT(PORTAB_LINE_LED1), PAL_PAD(PORTAB_LINE_LED1), PAL_WB32_MODE_OUTPUT | PAL_WB32_OTYPE_PUSHPULL);
|
|
|
|
palSetPadMode(PAL_PORT(PORTAB_LINE_LED2), PAL_PAD(PORTAB_LINE_LED2), PAL_WB32_MODE_OUTPUT | PAL_WB32_OTYPE_PUSHPULL);
|
|
|
|
|
2022-03-22 02:14:05 -07:00
|
|
|
/*
|
2022-05-12 00:32:34 -07:00
|
|
|
* Configure PA0 in interrupt mode
|
2022-03-22 02:14:05 -07:00
|
|
|
*/
|
2022-05-12 00:32:34 -07:00
|
|
|
EXTI0_Config();
|
2022-03-22 02:14:05 -07:00
|
|
|
|
2022-05-12 00:32:34 -07:00
|
|
|
#if defined(PORTAB_LINE_LED2)
|
2022-03-22 02:14:05 -07:00
|
|
|
/*
|
|
|
|
* Creates the blinker thread.
|
|
|
|
*/
|
|
|
|
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
2022-05-12 00:32:34 -07:00
|
|
|
#endif
|
2022-03-22 02:14:05 -07:00
|
|
|
|
|
|
|
/*
|
2022-05-12 00:32:34 -07:00
|
|
|
* Normal main() thread activity.
|
2022-03-22 02:14:05 -07:00
|
|
|
*/
|
2022-05-12 00:32:34 -07:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
/* Waiting for an edge on the button.*/
|
|
|
|
palWaitLineTimeout(PORTAB_LINE_BUTTON, TIME_INFINITE);
|
|
|
|
|
|
|
|
palToggleLine(PORTAB_LINE_LED1);
|
2022-03-22 02:14:05 -07:00
|
|
|
}
|
|
|
|
}
|
2022-05-12 00:32:34 -07:00
|
|
|
|
|
|
|
#endif /* PAL_USE_WAIT */
|