|
Simone: a game of visual memory and speed
|
Portable functions to interact with the RGB light system FSM library. All portable functions must be implemented in this file. More...
#include <stdio.h>#include "port_rgb_light.h"#include "port_system.h"#include "stm32f4_system.h"#include "stm32f4_rgb_light.h"Functions | |
| stm32f4_rgb_light_hw_t * | _stm32f4_rgb_light_get (uint8_t rgb_light_id) |
| Get the RGB light struct with the given ID. More... | |
| void | _timer_pwm_config (uint8_t rgb_light_id) |
| Configure the timer that controls the PWM of each one of the RGB LEDs of the RGB light system. More... | |
| void | port_rgb_light_init (uint8_t rgb_light_id) |
| Configure the HW specifications of a given RGB light. More... | |
| void | port_rgb_light_set_rgb (uint8_t rgb_light_id, rgb_color_t color) |
| Set the Capture/Compare register values for each channel of the RGB LED given a color. More... | |
Variables | |
| stm32f4_rgb_light_hw_t | rgb_lights_arr [] |
| Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform. More... | |
Portable functions to interact with the RGB light system FSM library. All portable functions must be implemented in this file.
| stm32f4_rgb_light_hw_t* _stm32f4_rgb_light_get | ( | uint8_t | rgb_light_id | ) |
Get the RGB light struct with the given ID.
| rgb_light_id | Button ID. |
| void _timer_pwm_config | ( | uint8_t | rgb_light_id | ) |
Configure the timer that controls the PWM of each one of the RGB LEDs of the RGB light system.
This function is called by the port_rgb_light_init() public function to configure the timer that controls the PWM of the RGB LEDs of the RGB light.
switch or if statement.*port_rgb_light_set_rgb() function where the color is set.TODO alumnos:
PWM timer setup
✅ 1. Enable the clock source of the timer
💡 To know if the source clock isAPB1orAPB2, check the clock tree in the user manual (Figure 3. STM32F446xC/E block diagram)
✅ 2. Disable the counter (registerCR1) and enable the autoreload preaload (bitARPE) ✅ 3. Reset the counter (registerCNT), set the autoreload value (registerARR) and the prescaler (registerPSC) for a frequency of 50 Hz.
PWM mode configuration
- Note
- Check table "Table 11. Alternate function" in the datasheet to select the channel more alternate functions.
✅ 5. Disable the output compare (register
CCER) for each one of the corresponding channels. Take into account the channel number (1, 2, 3, or 4) and the channel enable bit (CCxE)
✅ 6. Clear the P and NP bits (CCxP and CCxNP) of the output compare register (CCER) for each one of the corresponding channels .
✅ 7. Set both (i) mode PWM 1, and (ii) enable preload (register CCMRx) for each one of the corresponding channels.
💡 To set the mode PWM tomode 1you must set the bitsOCxMin theCCMRxregister to the corresponding values according to the explanations of the manufacturer. You can find it in the explanations for the TIMx_CCMRx register for timers TIM2-TIM5 in Sections 17.4.7 and 17.4.8 in the reference manual
💡 To enable the preload you must set the bitOCxPEto1in the same register. ✅ 8. Generate an update event (registerEGR) by setting theUGbit. This will load the values of theARRandPSCregisters into the active registers.
| rgb_light_id | RGB light system identifier number. |
| void port_rgb_light_init | ( | uint8_t | rgb_light_id | ) |
Configure the HW specifications of a given RGB light.
Assuming we are using an STM32F4-based platform, this function must call the following functions:
TODO alumnos:
✅ 1. Retrieve the RGB light configuration struct calling
_stm32f4_rgb_light_get().
✅ 2. Call functionstm32f4_system_gpio_config()with the right arguments to configure each RGB LED as in alternate mode and no pull up neither pull down connection.
✅ 3. Call functionstm32f4_system_gpio_config_alternate()with the right arguments to configure the alternate function of the each RGB LED.
✅ 4. Call function_timer_pwm_config()to configure the timer and the PWM signal of the RGB light.
✅ 5. Call functionport_rgb_light_set_rgb()to set the RGB LED to off.
| rgb_light_id | RGB light ID. This index is used to select the element of the rgb_lights_arr[] array |
| void port_rgb_light_set_rgb | ( | uint8_t | rgb_light_id, |
| rgb_color_t | color | ||
| ) |
Set the Capture/Compare register values for each channel of the RGB LED given a color.
This function disables the timer associated to the RGB LEDs, sets the Capture/Compare register values for each channel of the RGB LED, and enables the timer.
TODO alumnos:
✅ 1. Retrieve the individual RGB values from the
colorparameter and follow the flowchart given in the lab notebook to set the RGB LED color by configuring the PWM signals appropriately.
| rgb_light_id | RGB light system identifier number. |
| color | RGB color to set. |
| stm32f4_rgb_light_hw_t rgb_lights_arr[] |
Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform.
stm32f4_rgb_light.h. It represents an array of RGB lights.