53 lines
1.8 KiB
C
53 lines
1.8 KiB
C
#include "led_indicator_stm32_hal.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
void HAL_GPIO_WritePin(GPIO_TypeDef *gpio, uint16_t pin, GPIO_PinState state)
|
|
{
|
|
gpio->last_pin = pin;
|
|
gpio->last_state = state;
|
|
gpio->writes++;
|
|
}
|
|
|
|
#define CHECK(condition) \
|
|
do { \
|
|
if (!(condition)) { \
|
|
fprintf(stderr, "check failed at line %d: %s\n", __LINE__, \
|
|
#condition); \
|
|
return 1; \
|
|
} \
|
|
} while (0)
|
|
|
|
int main(void)
|
|
{
|
|
GPIO_TypeDef gpio_a = {0};
|
|
GPIO_TypeDef gpio_b = {0};
|
|
TIM_HandleTypeDef timer = {100U, 65535U};
|
|
const LedIndicator_Stm32HalOutput outputs[] = {
|
|
{&gpio_a, 0x0001U, 0U},
|
|
{&gpio_b, 0x0080U, 1U}
|
|
};
|
|
LedIndicator_Stm32HalPort adapter;
|
|
LedIndicator_Port port;
|
|
|
|
CHECK(LedIndicator_Stm32HalPortInit(&adapter, &timer, 10000U,
|
|
outputs, 2U, &port) != 0U);
|
|
port.write(port.context, 0U, 1U);
|
|
CHECK(gpio_a.last_pin == 0x0001U && gpio_a.last_state == GPIO_PIN_SET);
|
|
port.write(port.context, 1U, 1U);
|
|
CHECK(gpio_b.last_pin == 0x0080U && gpio_b.last_state == GPIO_PIN_RESET);
|
|
|
|
timer.counter = 109U;
|
|
CHECK(port.now_ms(port.context) == 0U);
|
|
timer.counter = 110U;
|
|
CHECK(port.now_ms(port.context) == 1U);
|
|
|
|
timer.counter = 65530U;
|
|
(void)port.now_ms(port.context);
|
|
timer.counter = 4U;
|
|
CHECK(port.now_ms(port.context) == 6544U);
|
|
|
|
puts("led indicator STM32 port tests passed");
|
|
return 0;
|
|
}
|