Commit b35662a4 authored by Luiz-Fernando Lavado-Villa's avatar Luiz-Fernando Lavado-Villa
Browse files

Updated some timer 4 details and a toggle led support

parent cd7159ac
......@@ -43,7 +43,7 @@
#define TIMER6_LABEL DT_PROP(DT_NODELABEL(timers6), label)
static const struct device* timer6 = NULL;
#define TIMER6_LABEL DT_PROP(DT_NODELABEL(timers4), label)
#define TIMER4_LABEL DT_PROP(DT_NODELABEL(timers4), label)
static const struct device* timer4 = NULL;
static uint32_t period;
......@@ -59,7 +59,6 @@ static struct gpio_dt_spec led_pin_spec = GPIO_DT_SPEC_GET(LED0_GPIO_NODE, gpios
//USART 1 defines
#define CONFIG_OWNTECH_SERIAL_TX_BUF_SIZE 5
#define CONFIG_OWNTECH_SERIAL_RX_BUF_SIZE 5
// #define LED0_GPIO_NODE DT_ALIAS(led0)
#define EXTRA_UART_DEVICE_NAME DT_PROP(DT_NODELABEL(usart1), label)
static const struct device* uart_dev = NULL;
......@@ -81,6 +80,8 @@ const struct uart_config usart1_config =
/////
// Private functions
// ----------------- PRIVATE FUNCTION DEDICATED TO INITIALIZE THE PERIODIC TASK -----------------------
static void _opalib_init_task(void (*periodic_task)(), uint32_t task_period_us)
{
// Configure timer
......@@ -96,6 +97,21 @@ static void _opalib_init_task(void (*periodic_task)(), uint32_t task_period_us)
}
static void _opalib_init_encoder()
{
// Configure timer
timer4 = device_get_binding(TIMER4_LABEL);
struct timer_config_t timer_cfg =
{
.timer_enable_irq = 0,
.timer_callback = NULL
};
timer_config(timer4, &timer_cfg);
}
// ----------------- PRIVATE FUNCTION OF THE USART 1 -----------------------
void _opalib_usart1_process_input(const struct device *dev, void* user_data)
{
......@@ -119,13 +135,7 @@ void _opalib_usart1_process_input(const struct device *dev, void* user_data)
/////
// Public API
void opalib_quick_start_init_led()
{
// Configure timer
gpio_pin_configure_dt(&led_pin_spec, GPIO_OUTPUT_ACTIVE);
}
// ----------------- FUNCTIONS DEDICATED TO THE PERIODIC TASK -----------------------
void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
{
......@@ -136,6 +146,14 @@ void opalib_quick_start_init(void (*periodic_task)(), uint32_t task_period_us)
}
}
void opalib_quick_start_launch_task()
{
timer_start(timer6, period);
}
// ----------------- FUNCTIONS DEDICATED TO THE USART 1 -----------------------
void opalib_quick_start_init_usart1()
{
uart_dev = device_get_binding(EXTRA_UART_DEVICE_NAME);
......@@ -154,21 +172,18 @@ char opalib_usart1_get_data()
}
}
void opalib_usart1_write_single(char data)
{
uart_poll_out(uart_dev,data);
}
void opalib_quick_start_launch_task()
{
timer_start(timer6, period);
}
// ----------------- FUNCTIONS DEDICATED TO THE ENCODER -----------------------
void opalib_quick_start_encoder_start()
{
// timer_start(timer4, 1);
init_timer_4();
//init_timer_4();
LL_TIM_EnableCounter(TIM4);
}
......@@ -178,6 +193,8 @@ uint32_t opalib_quick_start_encoder_get_step()
return LL_TIM_GetCounter(TIM4);
}
// ----------------- FUNCTIONS DEDICATED TO CHANGING SETUP ACCORDING TO THE HARDWARE VERSION -----------------------
void opalib_quick_start_set_hardware_version(hardware_version_t hardware_version)
{
......@@ -189,16 +206,32 @@ void opalib_quick_start_set_hardware_version(hardware_version_t hardware_version
}
}
// ----------------- FUNCTIONS DEDICATED TO THE LED -----------------------
void opalib_quick_start_init_led()
{
// Configure timer
gpio_pin_configure_dt(&led_pin_spec, GPIO_OUTPUT_ACTIVE);
}
void opalib_quick_start_led_on()
{
// sets the led state
// turns the led on
gpio_pin_set(led_pin_spec.port,led_pin_spec.pin,1);
}
void opalib_quick_start_led_off()
{
// sets the led state
// turns the led off
gpio_pin_set(led_pin_spec.port,led_pin_spec.pin,0);
}
void opalib_quick_start_led_toggle()
{
// toggles the led state
gpio_pin_toggle(led_pin_spec.port,led_pin_spec.pin);
}
......@@ -86,6 +86,16 @@ uint32_t opalib_quick_start_encoder_get_step();
*/
void opalib_quick_start_set_hardware_version(hardware_version_t hardware_version);
/**
* @brief Initializes the LED
*/
void opalib_quick_start_init_led();
/**
* @brief Toggles the led state
*/
void opalib_quick_start_led_toggle();
/**
* @brief Sets the LED on
*/
......@@ -96,10 +106,6 @@ void opalib_quick_start_led_on();
*/
void opalib_quick_start_led_off();
/**
* @brief Initializes the LED
*/
void opalib_quick_start_init_led();
/**
* @brief Library initialization function for the usart communication.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment