ARMEBS4  revision-26.06.2015
bsp.h
Go to the documentation of this file.
1 /************************************************************************//**
2  * \file heivs/bsp.h
3  * \brief BSP - Board Support Package
4  * \author marc dot pignat at hevs dot ch
5  ***************************************************************************/
6 
7 #ifndef HEIVS_BSP_H
8 #define HEIVS_BSP_H
9 /************************************************************************//**
10  * \defgroup bsp Board support package
11  * \ingroup libheivs_stm32
12  * @{
13  * \brief Support for common devices (buttons, leds, ...)
14  ***************************************************************************/
15 
16 #include "heivs/error.h"
17 #include "heivs/stm32_gpio.h"
18 
19 #if defined(BOARD_STM32F4_DISCOVERY)
21 #elif defined (BOARD_STM32F4_DISCOVERY_LCD)
22 #include "heivs/bsp_stm32f4_discovery_lcd.h"
23 #elif defined (BOARD_STM32F4_GEVAL)
25 #elif defined (BOARD_STM32_CAMERA)
26 #include "heivs/bsp_stm32_camera.h"
27 #elif defined (BOARD_ARMEBS4)
28 #include "heivs/bsp_armebs4.h"
29 #elif defined (BOARD_ENVIROBOT_SC)
30 #include "heivs/bsp_envirobot_sc.h"
31 #else
32 #error Please define BOARD_STM32F4_DISCOVERY, BOARD_STM32F4_GEVAL, BOARD_STM32_CAMERA or BOARD_ARMEBS4 globally
33 #endif
34 
35 #if !defined(BSP_LED_NR)
36 #error heivs/bsp_CURRENT_BOARD.h must define BSP_LED_NR
37 #endif
38 
39 #if !defined(BSP_BUTTON_NR)
40 #error heivs/bsp_CURRENT_BOARD.h must define BSP_BUTTON_NR
41 #endif
42 
43 #if !defined(BSP_I2C_BUS_COUNT)
44 #error heivs/bsp_CURRENT_BOARD.h must define BSP_I2C_BUS_COUNT
45 #endif
46 
47 #if !defined(BSP_SPI_BUS_COUNT)
48 #error heivs/bsp_CURRENT_BOARD.h must define BSP_SPI_BUS_COUNT
49 #endif
50 
51 #if !defined(BSP_USART_BUS_COUNT)
52 #error heivs/bsp_CURRENT_BOARD.h must define BSP_USART_BUS_COUNT
53 #endif
54 
55 /**
56  * \def BSP_BOARD_PRETTY_NAME
57  * \brief User friendly name
58  */
59 #if !defined(BSP_BOARD_PRETTY_NAME)
60 #error heivs/bsp_CURRENT_BOARD.h must define BSP_BOARD_PRETTY_NAME
61 #endif
62 
63 #if !defined(BSP_HAS_NVM)
64 #define BSP_HAS_NVM 0
65 #endif
66 
67 #if (BSP_HAS_NVM != 0) && (BSP_HAS_NVM != 1)
68 #error BSP_HAS_NVM should be defined as 0 or 1
69 #endif
70 
71 #ifdef __cplusplus
72  extern "C" {
73 #endif
74 
75 /************************************************************************//**
76  * \brief Initialize the whole board
77  *
78  * \return #NO_ERROR for no problem
79  ***************************************************************************/
80 status_e bsp_init(void);
81 
82 /************************************************************************//**
83  * \brief Set a led (ON or OFF)
84  * \param nr the led number
85  * \param value 0 for OFF, anything else : ON
86  *
87  ***************************************************************************/
88 void bsp_led_set(uint32_t nr, uint32_t value);
89 
90 #ifdef BSP_PWM_LED_STEPS
91 /************************************************************************//**
92  * \brief Set the value of a led
93  * \param led the led number, 0..BSP_LED_NR-1
94  * \param value the value from 0 to BSP_PWM_LED_STEPS, 0 is off
95  *
96  * \see BSP_LED_NR
97  * \see BSP_PWM_LED_STEPS
98  ***************************************************************************/
99 void bsp_led_set_pwm(uint32_t led, uint32_t value);
100 #else
101 //#define bsp_led_set_pwm(x,y) ERROR_your_BSP_does_not_support_pwm_leds
102 #endif
103 
104 /************************************************************************//**
105  * \brief Get a button
106  * \param nr the button number
107  * \return value 0 for "not pressed", anything else : "pressed"
108  ***************************************************************************/
109 uint32_t bsp_button_get(uint32_t nr);
110 
111 /************************************************************************//**
112  * \brief Get all buttons
113  *
114  * \return the value of each buttons stored in every bits of the return value
115  ***************************************************************************/
116 uint32_t bsp_button_get_all(void);
117 
118 /************************************************************************//**
119  * \brief get buttons gpios
120  * \return the pointer on the first element of an array of gpios
121  ***************************************************************************/
122 const struct gpio_t *bsp_button_gpios(void);
123 
124 /************************************************************************//**
125  * \brief Set a irq handler for all button changes
126  * \param handler The handler for button changed with those parameters is : the current value, was, the value of the last call
127  * \return #NO_ERROR for no problem
128  ***************************************************************************/
129 status_e bsp_set_button_irq_handler(void (*handler)(uint32_t is, uint32_t was));
130 
131 /************************************************************************//**
132  * \brief toggle a led
133  * \param nr the led number
134  ***************************************************************************/
135 void bsp_led_toggle(uint32_t nr);
136 
137 /************************************************************************//**
138  * \brief fatal error
139  *
140  * \param status The status of the fatal error
141  *
142  * This function will halt the CPU if a debugger is connected.
143  ***************************************************************************/
144 __attribute__ ((weak, noreturn))
145 void bsp_fatal(status_e status);
146 
147 /************************************************************************//**
148  * \brief Reset reason initialization
149  *
150  * Save the reset reason, called from startup code
151  ***************************************************************************/
152 void bsp_reset_reason_init(void);
153 
154 /************************************************************************//**
155  * \brief Reset reason get
156  * \return the value of RCC->CSR at boot time
157  *
158  * This value has been saved by bsp_reset_reason_init from startup code
159  ***************************************************************************/
160 uint32_t bsp_reset_reason_get(void);
161 
162 /************************************************************************//**
163  * \brief Reset reason clear
164  *
165  * Clear the reset reason value from RCC->CSR
166  ***************************************************************************/
167 void bsp_reset_reason_clear(void);
168 
169 #ifndef HSE_VALUE
170 extern uint32_t HSE_VALUE;
171 #endif
172 
173 #ifdef __cplusplus
174  }
175 #endif
176 
177 /************************************************************************//**
178  * @}
179  ***************************************************************************/
180 
181 #endif /* HEIVS_BSP_H */
uint8_t nr
Pin number (0 for GPIOx0, ... , 3 for GPIOx3, ...)
Definition: stm32_gpio.h:99
void bsp_reset_reason_clear(void)
Reset reason clear.
Definition: bsp.c:185
void bsp_fatal(status_e status)
fatal error
Definition: bsp.c:123
BSP for stm32f4 discovery.
Errors definitions.
void bsp_led_set(uint32_t nr, uint32_t value)
Set a led (ON or OFF)
Definition: bsp_armebs4.c:244
board specific defines
void bsp_led_toggle(uint32_t nr)
toggle a led
Definition: bsp_armebs4.c:249
BSP for ARMEBS4.
GPIO control structure.
Definition: stm32_gpio.h:96
status_e bsp_set_button_irq_handler(void(*handler)(uint32_t is, uint32_t was))
Set a irq handler for all button changes.
Definition: bsp.c:34
uint32_t bsp_reset_reason_get(void)
Reset reason get.
Definition: bsp.c:180
uint32_t bsp_button_get_all(void)
Get all buttons.
Definition: bsp.c:9
void bsp_reset_reason_init(void)
Reset reason initialization.
Definition: bsp.c:175
BSP for stm32f4 camera.
BSP for stm3240 g-eval board.
BSP for Envirobot Sensor Control.
status_e
Known errors.
Definition: error.h:21
const struct gpio_t * bsp_button_gpios(void)
get buttons gpios
Definition: bsp_armebs4.c:350
status_e bsp_init(void)
Initialize the whole board.
Definition: bsp_armebs4.c:525
uint32_t bsp_button_get(uint32_t nr)
Get a button.
Definition: bsp_armebs4.c:340