STM8S/A Standard Peripherals Firmware Library: stm8_128_eval.c Source File

STM8S/A

stm8_128_eval.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm8_128_eval.c
00004   * @author  MCD Application Team
00005   * @version V1.0.1
00006   * @date    30-September-2014
00007   * @brief   This file provides firmware functions to manage Leds, push-buttons
00008   *          and COM ports available on STM8S Evaluation Boards from STMicroelectronics.
00009   ******************************************************************************
00010   *
00011   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00012   * You may not use this file except in compliance with the License.
00013   * You may obtain a copy of the License at:
00014   *
00015   *        http://www.st.com/software_license_agreement_liberty_v2
00016   *
00017   * Unless required by applicable law or agreed to in writing, software 
00018   * distributed under the License is distributed on an "AS IS" BASIS, 
00019   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   * See the License for the specific language governing permissions and
00021   * limitations under the License.
00022   *
00023   ******************************************************************************
00024   */
00025 
00026 /* Includes ------------------------------------------------------------------*/
00027 #include "stm8_128_eval.h"
00028 #include "stm8s_spi.h"
00029 #include "stm8s_i2c.h"
00030 #include "stm8s_clk.h"
00031 
00032 /** @addtogroup Utilities
00033   * @{
00034   */
00035 
00036 /** @addtogroup STM8S_EVAL
00037   * @{
00038   */
00039 
00040 /** @addtogroup STM8_128_EVAL
00041   * @{
00042   */
00043 
00044 /** @defgroup STM8_128_EVAL_LOW_LEVEL
00045   * @brief This file provides firmware functions to manage Leds, push-buttons,
00046   *        COM ports, SD card on SPI and EEPROM (sEE) available on STM8_128-EVAL
00047   *        evaluation board from STMicroelectronics.
00048   * @{
00049   */
00050 
00051 /* Private types definition --------------------------------------------------*/
00052 /* Private defines -----------------------------------------------------------*/
00053 /* Private macros ------------------------------------------------------------*/
00054 
00055 
00056 /** @defgroup STM8_128_EVAL_LOW_LEVEL_Private_Variables
00057   * @{
00058   */
00059 GPIO_TypeDef* LED_PORT[LEDn] = {LED1_GPIO_PORT, LED2_GPIO_PORT, LED3_GPIO_PORT,
00060                                 LED4_GPIO_PORT};
00061 const uint8_t LED_PIN[LEDn] =
00062   {
00063     LED1_GPIO_PIN, LED2_GPIO_PIN, LED3_GPIO_PIN,
00064     LED4_GPIO_PIN
00065   };
00066 
00067 GPIO_TypeDef* BUTTON_PORT[BUTTONn] =
00068   {
00069     KEY_BUTTON_PORT, RIGHT_BUTTON_PORT,
00070     LEFT_BUTTON_PORT, UP_BUTTON_PORT,
00071     DOWN_BUTTON_PORT, SEL_BUTTON_PORT
00072   };
00073 const uint8_t BUTTON_PIN[BUTTONn] =
00074   {
00075     KEY_BUTTON_PIN, RIGHT_BUTTON_PIN,
00076     LEFT_BUTTON_PIN, UP_BUTTON_PIN,
00077     DOWN_BUTTON_PIN, SEL_BUTTON_PIN
00078   };
00079 
00080 const uint8_t BUTTON_EXTI[BUTTONn] =
00081   {
00082     KEY_BUTTON_EXTI_PORT, RIGHT_BUTTON_EXTI_PORT,
00083     LEFT_BUTTON_EXTI_PORT, UP_BUTTON_EXTI_PORT,
00084     DOWN_BUTTON_EXTI_PORT, SEL_BUTTON_EXTI_PORT
00085   };
00086 /**
00087   * @}
00088   */
00089 
00090 /* Private function prototypes -----------------------------------------------*/
00091 
00092 /** @defgroup STM8_128_EVAL_LOW_LEVEL_Private_Functions
00093   * @{
00094   */
00095 
00096 /**
00097   * @brief  Configures LED GPIO.
00098   * @param  Led: Specifies the Led to be configured.
00099   *   This parameter can be one of following parameters:
00100   *     @arg LED1
00101   *     @arg LED2
00102   *     @arg LED3
00103   *     @arg LED4
00104   * @retval None
00105   */
00106 void STM_EVAL_LEDInit(Led_TypeDef Led)
00107 {
00108   /* Configure the GPIO_LED pin */
00109   GPIO_Init(LED_PORT[Led], (GPIO_Pin_TypeDef)LED_PIN[Led], GPIO_MODE_OUT_PP_HIGH_FAST);
00110 }
00111 
00112 /**
00113   * @brief  Turns selected LED On.
00114   * @param  Led: Specifies the Led to be set on.
00115   *   This parameter can be one of following parameters:
00116   *     @arg LED1
00117   *     @arg LED2
00118   *     @arg LED3
00119   *     @arg LED4
00120   * @retval None
00121   */
00122 void STM_EVAL_LEDOn(Led_TypeDef Led)
00123 {
00124   LED_PORT[Led]->ODR |= (uint8_t)LED_PIN[Led];
00125 }
00126 
00127 /**
00128   * @brief  Turns selected LED Off.
00129   * @param  Led: Specifies the Led to be set off.
00130   *   This parameter can be one of following parameters:
00131   *     @arg LED1
00132   *     @arg LED2
00133   *     @arg LED3
00134   *     @arg LED4
00135   * @retval None
00136   */
00137 void STM_EVAL_LEDOff(Led_TypeDef Led)
00138 {
00139   LED_PORT[Led]->ODR &= (uint8_t)~LED_PIN[Led];
00140 }
00141 
00142 /**
00143   * @brief  Toggles the selected LED.
00144   * @param  Led: Specifies the Led to be toggled.
00145   *   This parameter can be one of following parameters:
00146   *     @arg LED1
00147   *     @arg LED2
00148   *     @arg LED3
00149   *     @arg LED4
00150   * @retval None
00151   */
00152 void STM_EVAL_LEDToggle(Led_TypeDef Led)
00153 {
00154   LED_PORT[Led]->ODR ^= (uint8_t)LED_PIN[Led];
00155 }
00156 
00157 /**
00158   * @brief  Configures Button GPIO and EXTI Line.
00159   * @param  Button: Specifies the Button to be configured.
00160   *   This parameter can be one of following parameters:
00161   *     @arg BUTTON_KEY: Key Push Button
00162   *     @arg BUTTON_RIGHT: Joystick Right Push Button
00163   *     @arg BUTTON_LEFT: Joystick Left Push Button
00164   *     @arg BUTTON_UP: Joystick Up Push Button
00165   *     @arg BUTTON_DOWN: Joystick Down Push Button
00166   *     @arg BUTTON_SEL: Joystick Sel Push Button
00167   * @param  Button_Mode: Specifies Button mode.
00168   *   This parameter can be one of following parameters:
00169   *     @arg BUTTON_MODE_GPIO: Button will be used as simple IO
00170   *     @arg BUTTON_MODE_EXTI: Button will be connected to EXTI pin (sensitive to falling trigger)
00171   * @retval None
00172   */
00173 void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
00174 {
00175 
00176   if (Button_Mode == BUTTON_MODE_EXTI)
00177   { /* Pin configured in input floating mode with interrupt enabled
00178                        --> connected to EXTIx Interrupt, where x:0..7 */
00179     GPIO_Init(BUTTON_PORT[Button], (GPIO_Pin_TypeDef)BUTTON_PIN[Button], GPIO_MODE_IN_FL_IT);
00180     EXTI_SetExtIntSensitivity((EXTI_Port_TypeDef)BUTTON_EXTI[Button], EXTI_SENSITIVITY_FALL_LOW);
00181   }
00182   else
00183   { /* Pin configured in input floating mode with interrupt disabled */
00184     GPIO_Init(BUTTON_PORT[Button], (GPIO_Pin_TypeDef)BUTTON_PIN[Button], GPIO_MODE_IN_FL_NO_IT);
00185   }
00186 }
00187 
00188 /**
00189   * @brief  Returns the selected Button state.
00190   * @param  Button: Specifies the Button to be checked.
00191   *   This parameter can be one of following parameters:
00192   *     @arg BUTTON_KEY: Key Push Button
00193   *     @arg BUTTON_RIGHT: Joystick Right Push Button
00194   *     @arg BUTTON_LEFT: Joystick Left Push Button
00195   *     @arg BUTTON_UP: Joystick Up Push Button
00196   *     @arg BUTTON_DOWN: Joystick Down Push Button
00197   *     @arg BUTTON_SEL: Joystick Sel Push Button
00198   * @retval The Button GPIO pin value.
00199   */
00200 uint8_t STM_EVAL_PBGetState(Button_TypeDef Button)
00201 {
00202   return GPIO_ReadInputPin(BUTTON_PORT[Button], (GPIO_Pin_TypeDef)BUTTON_PIN[Button]);
00203 }
00204 
00205 
00206 /**
00207   * @brief  DeInitializes the SD/SD communication.
00208   * @param  None
00209   * @retval None
00210   */
00211 void SD_LowLevel_DeInit(void)
00212 {
00213   SPI_Cmd(DISABLE); /*!< SD_SPI disable */
00214 
00215   /*!< SD_SPI Peripheral clock disable */
00216   CLK_PeripheralClockConfig(SD_SPI_CLK, DISABLE);
00217 
00218   /*!< Configure SD_SPI pins: SCK */
00219   GPIO_Init(SD_SPI_SCK_GPIO_PORT, SD_SPI_SCK_PIN, GPIO_MODE_IN_FL_NO_IT);
00220 
00221   /*!< Configure SD_SPI pins: MISO */
00222   GPIO_Init(SD_SPI_MISO_GPIO_PORT, SD_SPI_MISO_PIN, GPIO_MODE_IN_FL_NO_IT);
00223 
00224   /*!< Configure SD_SPI pins: MOSI */
00225   GPIO_Init(SD_SPI_MOSI_GPIO_PORT, SD_SPI_MOSI_PIN, GPIO_MODE_IN_FL_NO_IT);
00226 
00227   /*!< Configure SD_SPI_CS_PIN pin: SD Card CS pin */
00228   GPIO_Init(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_MODE_IN_FL_NO_IT);
00229 
00230   /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */
00231   GPIO_Init(SD_DETECT_GPIO_PORT, SD_DETECT_PIN, GPIO_MODE_IN_FL_NO_IT);
00232 }
00233 
00234 /**
00235   * @brief  Initializes the SD_SPI and CS pins.
00236   * @param  None
00237   * @retval None
00238   */
00239 void SD_LowLevel_Init(void)
00240 {
00241   /* Enable SPI clock */
00242   CLK_PeripheralClockConfig(SD_SPI_CLK, ENABLE);
00243 
00244   /* Set the MOSI,MISO and SCK at high level */
00245   GPIO_ExternalPullUpConfig(SD_SPI_SCK_GPIO_PORT, (GPIO_Pin_TypeDef)(SD_SPI_MISO_PIN | SD_SPI_MOSI_PIN | \
00246                             SD_SPI_SCK_PIN), ENABLE);
00247 
00248   /* SD_SPI Configuration */
00249   SPI_Init( SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_4, SPI_MODE_MASTER,
00250            SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX,
00251            SPI_NSS_SOFT, 0x07);
00252 
00253 
00254   /* SD_SPI enable */
00255   SPI_Cmd( ENABLE);
00256 
00257   /* Set MSD ChipSelect pin in Output push-pull high level */
00258   GPIO_Init(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_MODE_OUT_PP_HIGH_SLOW);
00259 }
00260 
00261 /**
00262   * @brief  DeInitializes peripherals used by the I2C EEPROM driver.
00263   * @param  None
00264   * @retval None
00265   */
00266 void sEE_LowLevel_DeInit(void)
00267 {
00268   /* sEE_I2C Peripheral Disable */
00269   I2C_Cmd(DISABLE);
00270 
00271   /* sEE_I2C DeInit */
00272   I2C_DeInit();
00273 
00274   /*!< sEE_I2C Peripheral clock disable */
00275   CLK_PeripheralClockConfig(sEE_I2C_CLK, DISABLE);
00276 
00277   /*!< GPIO configuration */
00278   /*!< Configure sEE_I2C pins: SCL */
00279   GPIO_Init(sEE_I2C_SCL_GPIO_PORT, sEE_I2C_SCL_PIN, GPIO_MODE_IN_PU_NO_IT);
00280 
00281   /*!< Configure sEE_I2C pins: SDA */
00282   GPIO_Init(sEE_I2C_SDA_GPIO_PORT, sEE_I2C_SDA_PIN, GPIO_MODE_IN_PU_NO_IT);
00283 }
00284 
00285 /**
00286   * @brief  Initializes peripherals used by the I2C EEPROM driver.
00287   * @param  None
00288   * @retval None
00289   */
00290 void sEE_LowLevel_Init(void)
00291 {
00292   /*!< sEE_I2C Peripheral clock enable */
00293   CLK_PeripheralClockConfig(sEE_I2C_CLK, ENABLE);
00294 
00295 }
00296 
00297 /**
00298   * @}
00299   */
00300 
00301 /**
00302   * @}
00303   */
00304 
00305 /**
00306   * @}
00307   */
00308 
00309 /**
00310   * @}
00311   */
00312 
00313 /**
00314   * @}
00315   */
00316 
00317 
00318 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM8 Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM8 8-bit Microcontrollers platform visit www.st.com