├── LICENSE.md ├── README.md └── include ├── stm8s.h ├── stm8s_adc1.h ├── stm8s_adc2.h ├── stm8s_awu.h ├── stm8s_beep.h ├── stm8s_can.h ├── stm8s_clk.h ├── stm8s_exti.h ├── stm8s_flash.h ├── stm8s_gpio.h ├── stm8s_i2c.h ├── stm8s_itc.h ├── stm8s_iwdg.h ├── stm8s_rst.h ├── stm8s_spi.h ├── stm8s_tim1.h ├── stm8s_tim2.h ├── stm8s_tim3.h ├── stm8s_tim4.h ├── stm8s_tim5.h ├── stm8s_tim6.h ├── stm8s_uart1.h ├── stm8s_uart2.h ├── stm8s_uart3.h ├── stm8s_uart4.h └── stm8s_wwdg.h /LICENSE.md: -------------------------------------------------------------------------------- 1 | SLA0044 Rev5/February 2018 2 | 3 | BY INSTALLING COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES (STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT. 4 | 5 | Under STMicroelectronics’ intellectual property rights, the redistribution, reproduction and use in source and binary forms of the software or any part thereof, with or without modification, are permitted provided that the following conditions are met: 6 | 1. Redistribution of source code (modified or not) must retain any copyright notice, this list of conditions and the disclaimer set forth below as items 10 and 11. 7 | 2. Redistributions in binary form, except as embedded into microcontroller or microprocessor device manufactured by or for STMicroelectronics or a software update for such device, must reproduce any copyright notice provided with the binary code, this list of conditions, and the disclaimer set forth below as items 10 and 11, in documentation and/or other materials provided with the distribution. 8 | 3. Neither the name of STMicroelectronics nor the names of other contributors to this software may be used to endorse or promote products derived from this software or part thereof without specific written permission. 9 | 4. This software or any part thereof, including modifications and/or derivative works of this software, must be used and execute solely and exclusively on or in combination with a microcontroller or microprocessor device manufactured by or for STMicroelectronics. 10 | 5. No use, reproduction or redistribution of this software partially or totally may be done in any manner that would subject this software to any Open Source Terms. “Open Source Terms” shall mean any open source license which requires as part of distribution of software that the source code of such software is distributed therewith or otherwise made available, or open source license that substantially complies with the Open Source definition specified at www.opensource.org and any other comparable open source license such as for example GNU General Public License (GPL), Eclipse Public License (EPL), Apache Software License, BSD license or MIT license. 11 | 6. STMicroelectronics has no obligation to provide any maintenance, support or updates for the software. 12 | 7. The software is and will remain the exclusive property of STMicroelectronics and its licensors. The recipient will not take any action that jeopardizes STMicroelectronics and its licensors' proprietary rights or acquire any rights in the software, except the limited rights specified hereunder. 13 | 8. The recipient shall comply with all applicable laws and regulations affecting the use of the software or any part thereof including any applicable export control law or regulation. 14 | 9. Redistribution and use of this software or any part thereof other than as permitted under this license is void and will automatically terminate your rights under this license. 15 | 10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 | 11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM8S header 2 | 3 | ## What is it? 4 | 5 | It is a collection of STM8S/STM8AF header definitions officially offered by STMicroelectronics but with some patch to enable [SDCC](http://sdcc.sourceforge.net/ "Small Device C Compiler") support. 6 | 7 | ## Currently supported targets 8 | 9 | * STM8S208 10 | * STM8S207 11 | * STM8S007 12 | * STM8AF52Ax 13 | * STM8AF62Ax 14 | * STM8S105 15 | * STM8S005 16 | * STM8AF626x 17 | * STM8AF622x 18 | * STM8S103 19 | * STM8S003 20 | * STM8S903 21 | * STM8S001 22 | 23 | ## Why a handful of STM8 SDCC example found over the internet did not use the official headers? 24 | 25 | Historically, libraries like the one you found here is not possible per ST licensing terms. 26 | 27 | Back then, the patch to support more compilers apart from the compilers ST officially supported would violate the license set by STMicroelectronics. 28 | At some point, ST released their libraries under more permissive licensing terms. Now, this is possible, but with some restrictions, please see `LICENSE.md` for more info. 29 | 30 | ## Aim of this repository 31 | 32 | * Keep the changes least intrusive to the official header files 33 | * Ease of library usage and dependency management via git submodules 34 | 35 | ## Contributing 36 | 37 | People just change and patch whatever works for them. I also patch the header files just to make them works on my use cases. The patches are far from perfect but they will keep progressing relying on contributions. Pull requests are very welcome and discussable. 38 | 39 | ## License 40 | 41 | All code in this repository is subjected to the [MCD-ST Liberty SW License Agreement V2](https://www.st.com/software_license_agreement_liberty_v2). Redistribution inside a project with a different license does not override the license on the header files in this repository. 42 | -------------------------------------------------------------------------------- /include/stm8s_adc1.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_adc1.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the prototypes/macros for the ADC1 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __STM8S_ADC1_H 29 | #define __STM8S_ADC1_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm8s.h" 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** @addtogroup ADC1_Exported_Types 37 | * @{ 38 | */ 39 | 40 | /** 41 | * @brief ADC1 clock prescaler selection 42 | */ 43 | 44 | typedef enum 45 | { 46 | ADC1_PRESSEL_FCPU_D2 = (uint8_t)0x00, /**< Prescaler selection fADC1 = fcpu/2 */ 47 | ADC1_PRESSEL_FCPU_D3 = (uint8_t)0x10, /**< Prescaler selection fADC1 = fcpu/3 */ 48 | ADC1_PRESSEL_FCPU_D4 = (uint8_t)0x20, /**< Prescaler selection fADC1 = fcpu/4 */ 49 | ADC1_PRESSEL_FCPU_D6 = (uint8_t)0x30, /**< Prescaler selection fADC1 = fcpu/6 */ 50 | ADC1_PRESSEL_FCPU_D8 = (uint8_t)0x40, /**< Prescaler selection fADC1 = fcpu/8 */ 51 | ADC1_PRESSEL_FCPU_D10 = (uint8_t)0x50, /**< Prescaler selection fADC1 = fcpu/10 */ 52 | ADC1_PRESSEL_FCPU_D12 = (uint8_t)0x60, /**< Prescaler selection fADC1 = fcpu/12 */ 53 | ADC1_PRESSEL_FCPU_D18 = (uint8_t)0x70 /**< Prescaler selection fADC1 = fcpu/18 */ 54 | } ADC1_PresSel_TypeDef; 55 | 56 | /** 57 | * @brief ADC1 External conversion trigger event selection 58 | */ 59 | typedef enum 60 | { 61 | ADC1_EXTTRIG_TIM = (uint8_t)0x00, /**< Conversion from Internal TIM1 TRGO event */ 62 | ADC1_EXTTRIG_GPIO = (uint8_t)0x10 /**< Conversion from External interrupt on ADC_ETR pin*/ 63 | } ADC1_ExtTrig_TypeDef; 64 | 65 | /** 66 | * @brief ADC1 data alignment 67 | */ 68 | typedef enum 69 | { 70 | ADC1_ALIGN_LEFT = (uint8_t)0x00, /**< Data alignment left */ 71 | ADC1_ALIGN_RIGHT = (uint8_t)0x08 /**< Data alignment right */ 72 | } ADC1_Align_TypeDef; 73 | 74 | /** 75 | * @brief ADC1 Interrupt source 76 | */ 77 | typedef enum 78 | { 79 | ADC1_IT_AWDIE = (uint16_t)0x010, /**< Analog WDG interrupt enable */ 80 | ADC1_IT_EOCIE = (uint16_t)0x020, /**< EOC interrupt enable */ 81 | ADC1_IT_AWD = (uint16_t)0x140, /**< Analog WDG status */ 82 | ADC1_IT_AWS0 = (uint16_t)0x110, /**< Analog channel 0 status */ 83 | ADC1_IT_AWS1 = (uint16_t)0x111, /**< Analog channel 1 status */ 84 | ADC1_IT_AWS2 = (uint16_t)0x112, /**< Analog channel 2 status */ 85 | ADC1_IT_AWS3 = (uint16_t)0x113, /**< Analog channel 3 status */ 86 | ADC1_IT_AWS4 = (uint16_t)0x114, /**< Analog channel 4 status */ 87 | ADC1_IT_AWS5 = (uint16_t)0x115, /**< Analog channel 5 status */ 88 | ADC1_IT_AWS6 = (uint16_t)0x116, /**< Analog channel 6 status */ 89 | ADC1_IT_AWS7 = (uint16_t)0x117, /**< Analog channel 7 status */ 90 | ADC1_IT_AWS8 = (uint16_t)0x118, /**< Analog channel 8 status */ 91 | ADC1_IT_AWS9 = (uint16_t)0x119, /**< Analog channel 9 status */ 92 | ADC1_IT_AWS12 = (uint16_t)0x11C, /**< Analog channel 12 status */ 93 | /* refer to product datasheet for channel 12 availability */ 94 | ADC1_IT_EOC = (uint16_t)0x080 /**< EOC pending bit */ 95 | 96 | } ADC1_IT_TypeDef; 97 | 98 | /** 99 | * @brief ADC1 Flags 100 | */ 101 | typedef enum 102 | { 103 | ADC1_FLAG_OVR = (uint8_t)0x41, /**< Overrun status flag */ 104 | ADC1_FLAG_AWD = (uint8_t)0x40, /**< Analog WDG status */ 105 | ADC1_FLAG_AWS0 = (uint8_t)0x10, /**< Analog channel 0 status */ 106 | ADC1_FLAG_AWS1 = (uint8_t)0x11, /**< Analog channel 1 status */ 107 | ADC1_FLAG_AWS2 = (uint8_t)0x12, /**< Analog channel 2 status */ 108 | ADC1_FLAG_AWS3 = (uint8_t)0x13, /**< Analog channel 3 status */ 109 | ADC1_FLAG_AWS4 = (uint8_t)0x14, /**< Analog channel 4 status */ 110 | ADC1_FLAG_AWS5 = (uint8_t)0x15, /**< Analog channel 5 status */ 111 | ADC1_FLAG_AWS6 = (uint8_t)0x16, /**< Analog channel 6 status */ 112 | ADC1_FLAG_AWS7 = (uint8_t)0x17, /**< Analog channel 7 status */ 113 | ADC1_FLAG_AWS8 = (uint8_t)0x18, /**< Analog channel 8 status*/ 114 | ADC1_FLAG_AWS9 = (uint8_t)0x19, /**< Analog channel 9 status */ 115 | ADC1_FLAG_AWS12 = (uint8_t)0x1C, /**< Analog channel 12 status */ 116 | /* refer to product datasheet for channel 12 availability */ 117 | ADC1_FLAG_EOC = (uint8_t)0x80 /**< EOC falg */ 118 | }ADC1_Flag_TypeDef; 119 | 120 | 121 | /** 122 | * @brief ADC1 schmitt Trigger 123 | */ 124 | typedef enum 125 | { 126 | ADC1_SCHMITTTRIG_CHANNEL0 = (uint8_t)0x00, /**< Schmitt trigger disable on AIN0 */ 127 | ADC1_SCHMITTTRIG_CHANNEL1 = (uint8_t)0x01, /**< Schmitt trigger disable on AIN1 */ 128 | ADC1_SCHMITTTRIG_CHANNEL2 = (uint8_t)0x02, /**< Schmitt trigger disable on AIN2 */ 129 | ADC1_SCHMITTTRIG_CHANNEL3 = (uint8_t)0x03, /**< Schmitt trigger disable on AIN3 */ 130 | ADC1_SCHMITTTRIG_CHANNEL4 = (uint8_t)0x04, /**< Schmitt trigger disable on AIN4 */ 131 | ADC1_SCHMITTTRIG_CHANNEL5 = (uint8_t)0x05, /**< Schmitt trigger disable on AIN5 */ 132 | ADC1_SCHMITTTRIG_CHANNEL6 = (uint8_t)0x06, /**< Schmitt trigger disable on AIN6 */ 133 | ADC1_SCHMITTTRIG_CHANNEL7 = (uint8_t)0x07, /**< Schmitt trigger disable on AIN7 */ 134 | ADC1_SCHMITTTRIG_CHANNEL8 = (uint8_t)0x08, /**< Schmitt trigger disable on AIN8 */ 135 | ADC1_SCHMITTTRIG_CHANNEL9 = (uint8_t)0x09, /**< Schmitt trigger disable on AIN9 */ 136 | ADC1_SCHMITTTRIG_CHANNEL12 = (uint8_t)0x0C, /**< Schmitt trigger disable on AIN12 */ 137 | /* refer to product datasheet for channel 12 availability */ 138 | ADC1_SCHMITTTRIG_ALL = (uint8_t)0xFF /**< Schmitt trigger disable on All channels */ 139 | } ADC1_SchmittTrigg_TypeDef; 140 | 141 | /** 142 | * @brief ADC1 conversion mode selection 143 | */ 144 | 145 | typedef enum 146 | { 147 | ADC1_CONVERSIONMODE_SINGLE = (uint8_t)0x00, /**< Single conversion mode */ 148 | ADC1_CONVERSIONMODE_CONTINUOUS = (uint8_t)0x01 /**< Continuous conversion mode */ 149 | } ADC1_ConvMode_TypeDef; 150 | 151 | /** 152 | * @brief ADC1 analog channel selection 153 | */ 154 | 155 | typedef enum 156 | { 157 | ADC1_CHANNEL_0 = (uint8_t)0x00, /**< Analog channel 0 */ 158 | ADC1_CHANNEL_1 = (uint8_t)0x01, /**< Analog channel 1 */ 159 | ADC1_CHANNEL_2 = (uint8_t)0x02, /**< Analog channel 2 */ 160 | ADC1_CHANNEL_3 = (uint8_t)0x03, /**< Analog channel 3 */ 161 | ADC1_CHANNEL_4 = (uint8_t)0x04, /**< Analog channel 4 */ 162 | ADC1_CHANNEL_5 = (uint8_t)0x05, /**< Analog channel 5 */ 163 | ADC1_CHANNEL_6 = (uint8_t)0x06, /**< Analog channel 6 */ 164 | ADC1_CHANNEL_7 = (uint8_t)0x07, /**< Analog channel 7 */ 165 | ADC1_CHANNEL_8 = (uint8_t)0x08, /**< Analog channel 8 */ 166 | ADC1_CHANNEL_9 = (uint8_t)0x09, /**< Analog channel 9 */ 167 | ADC1_CHANNEL_12 = (uint8_t)0x0C /**< Analog channel 12 */ 168 | /* refer to product datasheet for channel 12 availability */ 169 | } ADC1_Channel_TypeDef; 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /* Exported constants --------------------------------------------------------*/ 176 | 177 | /* Exported macros ------------------------------------------------------------*/ 178 | 179 | /* Private macros ------------------------------------------------------------*/ 180 | 181 | /** @addtogroup ADC1_Private_Macros 182 | * @brief Macros used by the assert function to check the different functions parameters. 183 | * @{ 184 | */ 185 | 186 | /** 187 | * @brief Macro used by the assert function to check the different prescaler's values. 188 | */ 189 | #define IS_ADC1_PRESSEL_OK(PRESCALER) (((PRESCALER) == ADC1_PRESSEL_FCPU_D2) || \ 190 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D3) || \ 191 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D4) || \ 192 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D6) || \ 193 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D8) || \ 194 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D10) || \ 195 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D12) || \ 196 | ((PRESCALER) == ADC1_PRESSEL_FCPU_D18)) 197 | 198 | /** 199 | * @brief Macro used by the assert function to check the different external trigger values. 200 | */ 201 | #define IS_ADC1_EXTTRIG_OK(EXTRIG) (((EXTRIG) == ADC1_EXTTRIG_TIM) || \ 202 | ((EXTRIG) == ADC1_EXTTRIG_GPIO)) 203 | 204 | /** 205 | * @brief Macro used by the assert function to check the different alignment modes. 206 | */ 207 | #define IS_ADC1_ALIGN_OK(ALIGN) (((ALIGN) == ADC1_ALIGN_LEFT) || \ 208 | ((ALIGN) == ADC1_ALIGN_RIGHT)) 209 | 210 | /** 211 | * @brief Macro used by the assert function to check the Interrupt source. 212 | */ 213 | #define IS_ADC1_IT_OK(IT) (((IT) == ADC1_IT_EOCIE) || \ 214 | ((IT) == ADC1_IT_AWDIE)) 215 | 216 | /** 217 | * @brief Macro used by the assert function to check the ADC1 Flag. 218 | */ 219 | #define IS_ADC1_FLAG_OK(FLAG) (((FLAG) == ADC1_FLAG_EOC)|| \ 220 | ((FLAG) == ADC1_FLAG_OVR) || \ 221 | ((FLAG) == ADC1_FLAG_AWD) || \ 222 | ((FLAG) == ADC1_FLAG_AWS0) || \ 223 | ((FLAG) == ADC1_FLAG_AWS1) || \ 224 | ((FLAG) == ADC1_FLAG_AWS2) || \ 225 | ((FLAG) == ADC1_FLAG_AWS3) || \ 226 | ((FLAG) == ADC1_FLAG_AWS4) || \ 227 | ((FLAG) == ADC1_FLAG_AWS5) || \ 228 | ((FLAG) == ADC1_FLAG_AWS6) || \ 229 | ((FLAG) == ADC1_FLAG_AWS7) || \ 230 | ((FLAG) == ADC1_FLAG_AWS8) || \ 231 | ((FLAG) == ADC1_FLAG_AWS9)) 232 | 233 | /** 234 | * @brief Macro used by the assert function to check the ADC1 pending bits. 235 | */ 236 | #define IS_ADC1_ITPENDINGBIT_OK(ITPENDINGBIT) (((ITPENDINGBIT) == ADC1_IT_EOC) || \ 237 | ((ITPENDINGBIT) == ADC1_IT_AWD) || \ 238 | ((ITPENDINGBIT) == ADC1_IT_AWS0) || \ 239 | ((ITPENDINGBIT) == ADC1_IT_AWS1) || \ 240 | ((ITPENDINGBIT) == ADC1_IT_AWS2) || \ 241 | ((ITPENDINGBIT) == ADC1_IT_AWS3) || \ 242 | ((ITPENDINGBIT) == ADC1_IT_AWS4) || \ 243 | ((ITPENDINGBIT) == ADC1_IT_AWS5) || \ 244 | ((ITPENDINGBIT) == ADC1_IT_AWS6) || \ 245 | ((ITPENDINGBIT) == ADC1_IT_AWS7) || \ 246 | ((ITPENDINGBIT) == ADC1_IT_AWS8) || \ 247 | ((ITPENDINGBIT) == ADC1_IT_AWS12) || \ 248 | ((ITPENDINGBIT) == ADC1_IT_AWS9)) 249 | 250 | /** 251 | * @brief Macro used by the assert function to check the different schmitt trigger values. 252 | */ 253 | #define IS_ADC1_SCHMITTTRIG_OK(SCHMITTTRIG) (((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL0) || \ 254 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL1) || \ 255 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL2) || \ 256 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL3) || \ 257 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL4) || \ 258 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL5) || \ 259 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL6) || \ 260 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL7) || \ 261 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL8) || \ 262 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL12) || \ 263 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_ALL) || \ 264 | ((SCHMITTTRIG) == ADC1_SCHMITTTRIG_CHANNEL9)) 265 | 266 | /** 267 | * @brief Macro used by the assert function to check the different conversion modes. 268 | */ 269 | #define IS_ADC1_CONVERSIONMODE_OK(MODE) (((MODE) == ADC1_CONVERSIONMODE_SINGLE) || \ 270 | ((MODE) == ADC1_CONVERSIONMODE_CONTINUOUS)) 271 | 272 | /** 273 | * @brief Macro used by the assert function to check the different channels values. 274 | */ 275 | #define IS_ADC1_CHANNEL_OK(CHANNEL) (((CHANNEL) == ADC1_CHANNEL_0) || \ 276 | ((CHANNEL) == ADC1_CHANNEL_1) || \ 277 | ((CHANNEL) == ADC1_CHANNEL_2) || \ 278 | ((CHANNEL) == ADC1_CHANNEL_3) || \ 279 | ((CHANNEL) == ADC1_CHANNEL_4) || \ 280 | ((CHANNEL) == ADC1_CHANNEL_5) || \ 281 | ((CHANNEL) == ADC1_CHANNEL_6) || \ 282 | ((CHANNEL) == ADC1_CHANNEL_7) || \ 283 | ((CHANNEL) == ADC1_CHANNEL_8) || \ 284 | ((CHANNEL) == ADC1_CHANNEL_12) || \ 285 | ((CHANNEL) == ADC1_CHANNEL_9)) 286 | 287 | /** 288 | * @brief Macro used by the assert function to check the possible buffer values. 289 | */ 290 | #define IS_ADC1_BUFFER_OK(BUFFER) ((BUFFER) <= (uint8_t)0x09) 291 | 292 | /** 293 | * @} 294 | */ 295 | 296 | /* Exported functions ------------------------------------------------------- */ 297 | 298 | /** @addtogroup ADC1_Exported_Functions 299 | * @{ 300 | */ 301 | void ADC1_DeInit(void); 302 | void ADC1_Init(ADC1_ConvMode_TypeDef ADC1_ConversionMode, 303 | ADC1_Channel_TypeDef ADC1_Channel, 304 | ADC1_PresSel_TypeDef ADC1_PrescalerSelection, 305 | ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, 306 | FunctionalState ADC1_ExtTriggerState, ADC1_Align_TypeDef ADC1_Align, 307 | ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, 308 | FunctionalState ADC1_SchmittTriggerState); 309 | void ADC1_Cmd(FunctionalState NewState); 310 | void ADC1_ScanModeCmd(FunctionalState NewState); 311 | void ADC1_DataBufferCmd(FunctionalState NewState); 312 | void ADC1_ITConfig(ADC1_IT_TypeDef ADC1_IT, FunctionalState NewState); 313 | void ADC1_PrescalerConfig(ADC1_PresSel_TypeDef ADC1_Prescaler); 314 | void ADC1_SchmittTriggerConfig(ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, 315 | FunctionalState NewState); 316 | void ADC1_ConversionConfig(ADC1_ConvMode_TypeDef ADC1_ConversionMode, 317 | ADC1_Channel_TypeDef ADC1_Channel, 318 | ADC1_Align_TypeDef ADC1_Align); 319 | void ADC1_ExternalTriggerConfig(ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, FunctionalState NewState); 320 | void ADC1_AWDChannelConfig(ADC1_Channel_TypeDef Channel, FunctionalState NewState); 321 | void ADC1_StartConversion(void); 322 | uint16_t ADC1_GetConversionValue(void); 323 | void ADC1_SetHighThreshold(uint16_t Threshold); 324 | void ADC1_SetLowThreshold(uint16_t Threshold); 325 | uint16_t ADC1_GetBufferValue(uint8_t Buffer); 326 | FlagStatus ADC1_GetAWDChannelStatus(ADC1_Channel_TypeDef Channel); 327 | FlagStatus ADC1_GetFlagStatus(ADC1_Flag_TypeDef Flag); 328 | void ADC1_ClearFlag(ADC1_Flag_TypeDef Flag); 329 | ITStatus ADC1_GetITStatus(ADC1_IT_TypeDef ITPendingBit); 330 | void ADC1_ClearITPendingBit(ADC1_IT_TypeDef ITPendingBit); 331 | /** 332 | * @} 333 | */ 334 | 335 | #endif /* __STM8S_ADC1_H */ 336 | 337 | 338 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 339 | -------------------------------------------------------------------------------- /include/stm8s_adc2.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_adc2.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the prototypes/macros for the ADC2 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8S_ADC2_H 31 | #define __STM8S_ADC2_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8s.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup ADC2_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief ADC2 clock prescaler selection 44 | */ 45 | 46 | typedef enum { 47 | ADC2_PRESSEL_FCPU_D2 = (uint8_t)0x00, /**< Prescaler selection fADC2 = fcpu/2 */ 48 | ADC2_PRESSEL_FCPU_D3 = (uint8_t)0x10, /**< Prescaler selection fADC2 = fcpu/3 */ 49 | ADC2_PRESSEL_FCPU_D4 = (uint8_t)0x20, /**< Prescaler selection fADC2 = fcpu/4 */ 50 | ADC2_PRESSEL_FCPU_D6 = (uint8_t)0x30, /**< Prescaler selection fADC2 = fcpu/6 */ 51 | ADC2_PRESSEL_FCPU_D8 = (uint8_t)0x40, /**< Prescaler selection fADC2 = fcpu/8 */ 52 | ADC2_PRESSEL_FCPU_D10 = (uint8_t)0x50, /**< Prescaler selection fADC2 = fcpu/10 */ 53 | ADC2_PRESSEL_FCPU_D12 = (uint8_t)0x60, /**< Prescaler selection fADC2 = fcpu/12 */ 54 | ADC2_PRESSEL_FCPU_D18 = (uint8_t)0x70 /**< Prescaler selection fADC2 = fcpu/18 */ 55 | } ADC2_PresSel_TypeDef; 56 | 57 | /** 58 | * @brief ADC2 External conversion trigger event selection 59 | */ 60 | typedef enum { 61 | ADC2_EXTTRIG_TIM = (uint8_t)0x00, /**< Conversion from Internal TIM TRGO event */ 62 | ADC2_EXTTRIG_GPIO = (uint8_t)0x01 /**< Conversion from External interrupt on ADC_ETR pin*/ 63 | } ADC2_ExtTrig_TypeDef; 64 | 65 | /** 66 | * @brief ADC2 data alignment 67 | */ 68 | typedef enum { 69 | ADC2_ALIGN_LEFT = (uint8_t)0x00, /**< Data alignment left */ 70 | ADC2_ALIGN_RIGHT = (uint8_t)0x08 /**< Data alignment right */ 71 | } ADC2_Align_TypeDef; 72 | 73 | /** 74 | * @brief ADC2 schmitt Trigger 75 | */ 76 | typedef enum { 77 | ADC2_SCHMITTTRIG_CHANNEL0 = (uint8_t)0x00, /**< Schmitt trigger disable on AIN0 */ 78 | ADC2_SCHMITTTRIG_CHANNEL1 = (uint8_t)0x01, /**< Schmitt trigger disable on AIN1 */ 79 | ADC2_SCHMITTTRIG_CHANNEL2 = (uint8_t)0x02, /**< Schmitt trigger disable on AIN2 */ 80 | ADC2_SCHMITTTRIG_CHANNEL3 = (uint8_t)0x03, /**< Schmitt trigger disable on AIN3 */ 81 | ADC2_SCHMITTTRIG_CHANNEL4 = (uint8_t)0x04, /**< Schmitt trigger disable on AIN4 */ 82 | ADC2_SCHMITTTRIG_CHANNEL5 = (uint8_t)0x05, /**< Schmitt trigger disable on AIN5 */ 83 | ADC2_SCHMITTTRIG_CHANNEL6 = (uint8_t)0x06, /**< Schmitt trigger disable on AIN6 */ 84 | ADC2_SCHMITTTRIG_CHANNEL7 = (uint8_t)0x07, /**< Schmitt trigger disable on AIN7 */ 85 | ADC2_SCHMITTTRIG_CHANNEL8 = (uint8_t)0x08, /**< Schmitt trigger disable on AIN8 */ 86 | ADC2_SCHMITTTRIG_CHANNEL9 = (uint8_t)0x09, /**< Schmitt trigger disable on AIN9 */ 87 | ADC2_SCHMITTTRIG_CHANNEL10 = (uint8_t)0x0A, /**< Schmitt trigger disable on AIN10 */ 88 | ADC2_SCHMITTTRIG_CHANNEL11 = (uint8_t)0x0B, /**< Schmitt trigger disable on AIN11 */ 89 | ADC2_SCHMITTTRIG_CHANNEL12 = (uint8_t)0x0C, /**< Schmitt trigger disable on AIN12 */ 90 | ADC2_SCHMITTTRIG_CHANNEL13 = (uint8_t)0x0D, /**< Schmitt trigger disable on AIN13 */ 91 | ADC2_SCHMITTTRIG_CHANNEL14 = (uint8_t)0x0E, /**< Schmitt trigger disable on AIN14 */ 92 | ADC2_SCHMITTTRIG_CHANNEL15 = (uint8_t)0x0F, /**< Schmitt trigger disable on AIN15 */ 93 | ADC2_SCHMITTTRIG_ALL = (uint8_t)0x1F /**< Schmitt trigger disable on all channels */ 94 | 95 | } ADC2_SchmittTrigg_TypeDef; 96 | 97 | /** 98 | * @brief ADC2 conversion mode selection 99 | */ 100 | 101 | typedef enum { 102 | ADC2_CONVERSIONMODE_SINGLE = (uint8_t)0x00, /**< Single conversion mode */ 103 | ADC2_CONVERSIONMODE_CONTINUOUS = (uint8_t)0x01 /**< Continuous conversion mode */ 104 | } ADC2_ConvMode_TypeDef; 105 | 106 | /** 107 | * @brief ADC2 analog channel selection 108 | */ 109 | 110 | typedef enum { 111 | ADC2_CHANNEL_0 = (uint8_t)0x00, /**< Analog channel 0 */ 112 | ADC2_CHANNEL_1 = (uint8_t)0x01, /**< Analog channel 1 */ 113 | ADC2_CHANNEL_2 = (uint8_t)0x02, /**< Analog channel 2 */ 114 | ADC2_CHANNEL_3 = (uint8_t)0x03, /**< Analog channel 3 */ 115 | ADC2_CHANNEL_4 = (uint8_t)0x04, /**< Analog channel 4 */ 116 | ADC2_CHANNEL_5 = (uint8_t)0x05, /**< Analog channel 5 */ 117 | ADC2_CHANNEL_6 = (uint8_t)0x06, /**< Analog channel 6 */ 118 | ADC2_CHANNEL_7 = (uint8_t)0x07, /**< Analog channel 7 */ 119 | ADC2_CHANNEL_8 = (uint8_t)0x08, /**< Analog channel 8 */ 120 | ADC2_CHANNEL_9 = (uint8_t)0x09, /**< Analog channel 9 */ 121 | ADC2_CHANNEL_10 = (uint8_t)0x0A, /**< Analog channel 10 */ 122 | ADC2_CHANNEL_11 = (uint8_t)0x0B, /**< Analog channel 11 */ 123 | ADC2_CHANNEL_12 = (uint8_t)0x0C, /**< Analog channel 12 */ 124 | ADC2_CHANNEL_13 = (uint8_t)0x0D, /**< Analog channel 13 */ 125 | ADC2_CHANNEL_14 = (uint8_t)0x0E, /**< Analog channel 14 */ 126 | ADC2_CHANNEL_15 = (uint8_t)0x0F /**< Analog channel 15 */ 127 | } ADC2_Channel_TypeDef; 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /* Exported constants --------------------------------------------------------*/ 134 | 135 | /* Exported macros ------------------------------------------------------------*/ 136 | 137 | /* Private macros ------------------------------------------------------------*/ 138 | 139 | /** @addtogroup ADC2_Private_Macros 140 | * @brief Macros used by the assert function to check the different functions parameters. 141 | * @{ 142 | */ 143 | 144 | /** 145 | * @brief Macro used by the assert function to check the different prescaler's values. 146 | */ 147 | #define IS_ADC2_PRESSEL_OK(PRESCALER) (((PRESCALER) == ADC2_PRESSEL_FCPU_D2) || \ 148 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D3) || \ 149 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D4) || \ 150 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D6) || \ 151 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D8) || \ 152 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D10) || \ 153 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D12) || \ 154 | ((PRESCALER) == ADC2_PRESSEL_FCPU_D18)) 155 | 156 | /** 157 | * @brief Macro used by the assert function to check the different external trigger values. 158 | */ 159 | #define IS_ADC2_EXTTRIG_OK(EXTRIG) (((EXTRIG) == ADC2_EXTTRIG_TIM) || \ 160 | ((EXTRIG) == ADC2_EXTTRIG_GPIO)) 161 | 162 | /** 163 | * @brief Macro used by the assert function to check the different alignment modes. 164 | */ 165 | #define IS_ADC2_ALIGN_OK(ALIGN) (((ALIGN) == ADC2_ALIGN_LEFT) || \ 166 | ((ALIGN) == ADC2_ALIGN_RIGHT)) 167 | 168 | 169 | /** 170 | * @brief Macro used by the assert function to check the different schmitt trigger values. 171 | */ 172 | #define IS_ADC2_SCHMITTTRIG_OK(SCHMITTTRIG) (((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL0) || \ 173 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL1) || \ 174 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL2) || \ 175 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL3) || \ 176 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL4) || \ 177 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL5) || \ 178 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL6) || \ 179 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL7) || \ 180 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL8) || \ 181 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL9) || \ 182 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL10) || \ 183 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL11) || \ 184 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL12) || \ 185 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL13) || \ 186 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL14) || \ 187 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL15) || \ 188 | ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_ALL)) 189 | 190 | /** 191 | * @brief Macro used by the assert function to check the different conversion modes. 192 | */ 193 | #define IS_ADC2_CONVERSIONMODE_OK(MODE) (((MODE) == ADC2_CONVERSIONMODE_SINGLE) || \ 194 | ((MODE) == ADC2_CONVERSIONMODE_CONTINUOUS)) 195 | 196 | /** 197 | * @brief Macro used by the assert function to check the different channels values. 198 | */ 199 | #define IS_ADC2_CHANNEL_OK(CHANNEL) (((CHANNEL) == ADC2_CHANNEL_0) || \ 200 | ((CHANNEL) == ADC2_CHANNEL_1) || \ 201 | ((CHANNEL) == ADC2_CHANNEL_2) || \ 202 | ((CHANNEL) == ADC2_CHANNEL_3) || \ 203 | ((CHANNEL) == ADC2_CHANNEL_4) || \ 204 | ((CHANNEL) == ADC2_CHANNEL_5) || \ 205 | ((CHANNEL) == ADC2_CHANNEL_6) || \ 206 | ((CHANNEL) == ADC2_CHANNEL_7) || \ 207 | ((CHANNEL) == ADC2_CHANNEL_8) || \ 208 | ((CHANNEL) == ADC2_CHANNEL_9) || \ 209 | ((CHANNEL) == ADC2_CHANNEL_10) || \ 210 | ((CHANNEL) == ADC2_CHANNEL_11) || \ 211 | ((CHANNEL) == ADC2_CHANNEL_12) || \ 212 | ((CHANNEL) == ADC2_CHANNEL_13) || \ 213 | ((CHANNEL) == ADC2_CHANNEL_14) || \ 214 | ((CHANNEL) == ADC2_CHANNEL_15)) 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | /* Exported functions ------------------------------------------------------- */ 221 | 222 | /** @addtogroup ADC2_Exported_Functions 223 | * @{ 224 | */ 225 | void ADC2_DeInit(void); 226 | void ADC2_Init(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 227 | ADC2_Channel_TypeDef ADC2_Channel, 228 | ADC2_PresSel_TypeDef ADC2_PrescalerSelection, 229 | ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, 230 | FunctionalState ADC2_ExtTriggerState, 231 | ADC2_Align_TypeDef ADC2_Align, 232 | ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 233 | FunctionalState ADC2_SchmittTriggerState); 234 | void ADC2_Cmd(FunctionalState NewState); 235 | void ADC2_ITConfig(FunctionalState NewState); 236 | void ADC2_PrescalerConfig(ADC2_PresSel_TypeDef ADC2_Prescaler); 237 | void ADC2_SchmittTriggerConfig(ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel, 238 | FunctionalState NewState); 239 | void ADC2_ConversionConfig(ADC2_ConvMode_TypeDef ADC2_ConversionMode, 240 | ADC2_Channel_TypeDef ADC2_Channel, 241 | ADC2_Align_TypeDef ADC2_Align); 242 | void ADC2_ExternalTriggerConfig(ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, FunctionalState NewState); 243 | void ADC2_StartConversion(void); 244 | uint16_t ADC2_GetConversionValue(void); 245 | FlagStatus ADC2_GetFlagStatus(void); 246 | void ADC2_ClearFlag(void); 247 | ITStatus ADC2_GetITStatus(void); 248 | void ADC2_ClearITPendingBit(void); 249 | /** 250 | * @} 251 | */ 252 | 253 | #endif /* __STM8S_ADC2_H */ 254 | 255 | 256 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 257 | -------------------------------------------------------------------------------- /include/stm8s_awu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_awu.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the AWU peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_AWU_H 30 | #define __STM8S_AWU_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup AWU_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief AWU TimeBase selection 43 | */ 44 | 45 | typedef enum 46 | { 47 | AWU_TIMEBASE_NO_IT = (uint8_t)0, /*!< No AWU interrupt selected */ 48 | AWU_TIMEBASE_250US = (uint8_t)1, /*!< AWU Timebase equals 0.25 ms */ 49 | AWU_TIMEBASE_500US = (uint8_t)2, /*!< AWU Timebase equals 0.5 ms */ 50 | AWU_TIMEBASE_1MS = (uint8_t)3, /*!< AWU Timebase equals 1 ms */ 51 | AWU_TIMEBASE_2MS = (uint8_t)4, /*!< AWU Timebase equals 2 ms */ 52 | AWU_TIMEBASE_4MS = (uint8_t)5, /*!< AWU Timebase equals 4 ms */ 53 | AWU_TIMEBASE_8MS = (uint8_t)6, /*!< AWU Timebase equals 8 ms */ 54 | AWU_TIMEBASE_16MS = (uint8_t)7, /*!< AWU Timebase equals 16 ms */ 55 | AWU_TIMEBASE_32MS = (uint8_t)8, /*!< AWU Timebase equals 32 ms */ 56 | AWU_TIMEBASE_64MS = (uint8_t)9, /*!< AWU Timebase equals 64 ms */ 57 | AWU_TIMEBASE_128MS = (uint8_t)10, /*!< AWU Timebase equals 128 ms */ 58 | AWU_TIMEBASE_256MS = (uint8_t)11, /*!< AWU Timebase equals 256 ms */ 59 | AWU_TIMEBASE_512MS = (uint8_t)12, /*!< AWU Timebase equals 512 ms */ 60 | AWU_TIMEBASE_1S = (uint8_t)13, /*!< AWU Timebase equals 1 s */ 61 | AWU_TIMEBASE_2S = (uint8_t)14, /*!< AWU Timebase equals 2 s */ 62 | AWU_TIMEBASE_12S = (uint8_t)15, /*!< AWU Timebase equals 12 s */ 63 | AWU_TIMEBASE_30S = (uint8_t)16 /*!< AWU Timebase equals 30 s */ 64 | } AWU_Timebase_TypeDef; 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /* Exported constants --------------------------------------------------------*/ 71 | 72 | /** @addtogroup AWU_Exported_Constants 73 | * @{ 74 | */ 75 | 76 | #define LSI_FREQUENCY_MIN ((uint32_t)110000) /*!< LSI minimum value in Hertz */ 77 | #define LSI_FREQUENCY_MAX ((uint32_t)150000) /*!< LSI maximum value in Hertz */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /* Exported macros ------------------------------------------------------------*/ 84 | 85 | /* Private macros ------------------------------------------------------------*/ 86 | 87 | /** @addtogroup AWU_Private_Macros 88 | * @{ 89 | */ 90 | 91 | /** 92 | * @brief Macro used by the assert function to check the different functions parameters. 93 | */ 94 | 95 | /** 96 | * @brief Macro used by the assert function to check the AWU timebases 97 | */ 98 | #define IS_AWU_TIMEBASE_OK(TB) \ 99 | (((TB) == AWU_TIMEBASE_NO_IT) || \ 100 | ((TB) == AWU_TIMEBASE_250US) || \ 101 | ((TB) == AWU_TIMEBASE_500US) || \ 102 | ((TB) == AWU_TIMEBASE_1MS) || \ 103 | ((TB) == AWU_TIMEBASE_2MS) || \ 104 | ((TB) == AWU_TIMEBASE_4MS) || \ 105 | ((TB) == AWU_TIMEBASE_8MS) || \ 106 | ((TB) == AWU_TIMEBASE_16MS) || \ 107 | ((TB) == AWU_TIMEBASE_32MS) || \ 108 | ((TB) == AWU_TIMEBASE_64MS) || \ 109 | ((TB) == AWU_TIMEBASE_128MS) || \ 110 | ((TB) == AWU_TIMEBASE_256MS) || \ 111 | ((TB) == AWU_TIMEBASE_512MS) || \ 112 | ((TB) == AWU_TIMEBASE_1S) || \ 113 | ((TB) == AWU_TIMEBASE_2S) || \ 114 | ((TB) == AWU_TIMEBASE_12S) || \ 115 | ((TB) == AWU_TIMEBASE_30S)) 116 | 117 | /** 118 | * @brief Macro used by the assert function to check the LSI frequency (in Hz) 119 | */ 120 | #define IS_LSI_FREQUENCY_OK(FREQ) \ 121 | (((FREQ) >= LSI_FREQUENCY_MIN) && \ 122 | ((FREQ) <= LSI_FREQUENCY_MAX)) 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /* Exported functions ------------------------------------------------------- */ 129 | 130 | /** @addtogroup AWU_Exported_Functions 131 | * @{ 132 | */ 133 | void AWU_DeInit(void); 134 | void AWU_Init(AWU_Timebase_TypeDef AWU_TimeBase); 135 | void AWU_Cmd(FunctionalState NewState); 136 | void AWU_LSICalibrationConfig(uint32_t LSIFreqHz); 137 | void AWU_IdleModeEnable(void); 138 | FlagStatus AWU_GetFlagStatus(void); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #endif /* __STM8S_AWU_H */ 145 | 146 | 147 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 148 | -------------------------------------------------------------------------------- /include/stm8s_beep.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_beep.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the BEEP peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8S_BEEP_H 31 | #define __STM8S_BEEP_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8s.h" 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup BEEP_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief BEEP Frequency selection 44 | */ 45 | typedef enum { 46 | BEEP_FREQUENCY_1KHZ = (uint8_t)0x00, /*!< Beep signal output frequency equals to 1 KHz */ 47 | BEEP_FREQUENCY_2KHZ = (uint8_t)0x40, /*!< Beep signal output frequency equals to 2 KHz */ 48 | BEEP_FREQUENCY_4KHZ = (uint8_t)0x80 /*!< Beep signal output frequency equals to 4 KHz */ 49 | } BEEP_Frequency_TypeDef; 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /* Exported constants --------------------------------------------------------*/ 56 | 57 | /** @addtogroup BEEP_Exported_Constants 58 | * @{ 59 | */ 60 | 61 | #define BEEP_CALIBRATION_DEFAULT ((uint8_t)0x0B) /*!< Default value when calibration is not done */ 62 | 63 | #define LSI_FREQUENCY_MIN ((uint32_t)110000) /*!< LSI minimum value in Hertz */ 64 | #define LSI_FREQUENCY_MAX ((uint32_t)150000) /*!< LSI maximum value in Hertz */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /* Exported macros -----------------------------------------------------------*/ 71 | /* Private macros ------------------------------------------------------------*/ 72 | 73 | /** @addtogroup BEEP_Private_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @brief Macro used by the assert function to check the different functions parameters. 79 | */ 80 | 81 | /** 82 | * @brief Macro used by the assert function to check the BEEP frequencies. 83 | */ 84 | #define IS_BEEP_FREQUENCY_OK(FREQ) \ 85 | (((FREQ) == BEEP_FREQUENCY_1KHZ) || \ 86 | ((FREQ) == BEEP_FREQUENCY_2KHZ) || \ 87 | ((FREQ) == BEEP_FREQUENCY_4KHZ)) 88 | 89 | /** 90 | * @brief Macro used by the assert function to check the LSI frequency (in Hz). 91 | */ 92 | #define IS_LSI_FREQUENCY_OK(FREQ) \ 93 | (((FREQ) >= LSI_FREQUENCY_MIN) && \ 94 | ((FREQ) <= LSI_FREQUENCY_MAX)) 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /* Exported functions ------------------------------------------------------- */ 101 | 102 | /** @addtogroup BEEP_Exported_Functions 103 | * @{ 104 | */ 105 | 106 | void BEEP_DeInit(void); 107 | void BEEP_Init(BEEP_Frequency_TypeDef BEEP_Frequency); 108 | void BEEP_Cmd(FunctionalState NewState); 109 | void BEEP_LSICalibrationConfig(uint32_t LSIFreqHz); 110 | 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | #endif /* __STM8S_BEEP_H */ 117 | 118 | 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /include/stm8s_clk.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_clk.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the CLK peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8S_CLK_H 31 | #define __STM8S_CLK_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | /* Contains the description of all STM8 hardware registers */ 35 | #include "stm8s.h" 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /** @addtogroup CLK_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief Switch Mode Auto, Manual. 44 | */ 45 | typedef enum { 46 | CLK_SWITCHMODE_MANUAL = (uint8_t)0x00, /*!< Enable the manual clock switching mode */ 47 | CLK_SWITCHMODE_AUTO = (uint8_t)0x01 /*!< Enable the automatic clock switching mode */ 48 | } CLK_SwitchMode_TypeDef; 49 | 50 | /** 51 | * @brief Current Clock State. 52 | */ 53 | typedef enum { 54 | CLK_CURRENTCLOCKSTATE_DISABLE = (uint8_t)0x00, /*!< Current clock disable */ 55 | CLK_CURRENTCLOCKSTATE_ENABLE = (uint8_t)0x01 /*!< Current clock enable */ 56 | } CLK_CurrentClockState_TypeDef; 57 | 58 | /** 59 | * @brief Clock security system configuration. 60 | */ 61 | typedef enum { 62 | CLK_CSSCONFIG_ENABLEWITHIT = (uint8_t)0x05, /*!< Enable CSS with detection interrupt */ 63 | CLK_CSSCONFIG_ENABLE = (uint8_t)0x01, /*!< Enable CSS without detection interrupt */ 64 | CLK_CSSCONFIG_DISABLE = (uint8_t)0x00 /*!< Leave CSS desactivated (to be used in CLK_Init() function) */ 65 | } CLK_CSSConfig_TypeDef; 66 | 67 | /** 68 | * @brief CLK Clock Source. 69 | */ 70 | typedef enum { 71 | CLK_SOURCE_HSI = (uint8_t)0xE1, /*!< Clock Source HSI. */ 72 | CLK_SOURCE_LSI = (uint8_t)0xD2, /*!< Clock Source LSI. */ 73 | CLK_SOURCE_HSE = (uint8_t)0xB4 /*!< Clock Source HSE. */ 74 | } CLK_Source_TypeDef; 75 | 76 | /** 77 | * @brief CLK HSI Calibration Value. 78 | */ 79 | typedef enum { 80 | CLK_HSITRIMVALUE_0 = (uint8_t)0x00, /*!< HSI Calibration Value 0 */ 81 | CLK_HSITRIMVALUE_1 = (uint8_t)0x01, /*!< HSI Calibration Value 1 */ 82 | CLK_HSITRIMVALUE_2 = (uint8_t)0x02, /*!< HSI Calibration Value 2 */ 83 | CLK_HSITRIMVALUE_3 = (uint8_t)0x03, /*!< HSI Calibration Value 3 */ 84 | CLK_HSITRIMVALUE_4 = (uint8_t)0x04, /*!< HSI Calibration Value 4 */ 85 | CLK_HSITRIMVALUE_5 = (uint8_t)0x05, /*!< HSI Calibration Value 5 */ 86 | CLK_HSITRIMVALUE_6 = (uint8_t)0x06, /*!< HSI Calibration Value 6 */ 87 | CLK_HSITRIMVALUE_7 = (uint8_t)0x07 /*!< HSI Calibration Value 7 */ 88 | } CLK_HSITrimValue_TypeDef; 89 | 90 | /** 91 | * @brief CLK Clock Output 92 | */ 93 | typedef enum { 94 | CLK_OUTPUT_HSI = (uint8_t)0x00, /*!< Clock Output HSI */ 95 | CLK_OUTPUT_LSI = (uint8_t)0x02, /*!< Clock Output LSI */ 96 | CLK_OUTPUT_HSE = (uint8_t)0x04, /*!< Clock Output HSE */ 97 | CLK_OUTPUT_CPU = (uint8_t)0x08, /*!< Clock Output CPU */ 98 | CLK_OUTPUT_CPUDIV2 = (uint8_t)0x0A, /*!< Clock Output CPU/2 */ 99 | CLK_OUTPUT_CPUDIV4 = (uint8_t)0x0C, /*!< Clock Output CPU/4 */ 100 | CLK_OUTPUT_CPUDIV8 = (uint8_t)0x0E, /*!< Clock Output CPU/8 */ 101 | CLK_OUTPUT_CPUDIV16 = (uint8_t)0x10, /*!< Clock Output CPU/16 */ 102 | CLK_OUTPUT_CPUDIV32 = (uint8_t)0x12, /*!< Clock Output CPU/32 */ 103 | CLK_OUTPUT_CPUDIV64 = (uint8_t)0x14, /*!< Clock Output CPU/64 */ 104 | CLK_OUTPUT_HSIRC = (uint8_t)0x16, /*!< Clock Output HSI RC */ 105 | CLK_OUTPUT_MASTER = (uint8_t)0x18, /*!< Clock Output Master */ 106 | CLK_OUTPUT_OTHERS = (uint8_t)0x1A /*!< Clock Output OTHER */ 107 | } CLK_Output_TypeDef; 108 | 109 | /** 110 | * @brief CLK Enable peripheral 111 | */ 112 | /* Elements values convention: 0xXY 113 | X = choice between the peripheral registers 114 | X = 0 : PCKENR1 115 | X = 1 : PCKENR2 116 | Y = Peripheral position in the register 117 | */ 118 | typedef enum { 119 | CLK_PERIPHERAL_I2C = (uint8_t)0x00, /*!< Peripheral Clock Enable 1, I2C */ 120 | CLK_PERIPHERAL_SPI = (uint8_t)0x01, /*!< Peripheral Clock Enable 1, SPI */ 121 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || defined(STM8AF62Ax) 122 | CLK_PERIPHERAL_UART1 = (uint8_t)0x02, /*!< Peripheral Clock Enable 1, UART1 */ 123 | #else 124 | CLK_PERIPHERAL_UART1 = (uint8_t)0x03, /*!< Peripheral Clock Enable 1, UART1 */ 125 | #endif 126 | CLK_PERIPHERAL_UART2 = (uint8_t)0x03, /*!< Peripheral Clock Enable 1, UART2 */ 127 | CLK_PERIPHERAL_UART3 = (uint8_t)0x03, /*!< Peripheral Clock Enable 1, UART3 */ 128 | CLK_PERIPHERAL_TIMER6 = (uint8_t)0x04, /*!< Peripheral Clock Enable 1, Timer6 */ 129 | CLK_PERIPHERAL_TIMER4 = (uint8_t)0x04, /*!< Peripheral Clock Enable 1, Timer4 */ 130 | CLK_PERIPHERAL_TIMER5 = (uint8_t)0x05, /*!< Peripheral Clock Enable 1, Timer5 */ 131 | CLK_PERIPHERAL_TIMER2 = (uint8_t)0x05, /*!< Peripheral Clock Enable 1, Timer2 */ 132 | CLK_PERIPHERAL_TIMER3 = (uint8_t)0x06, /*!< Peripheral Clock Enable 1, Timer3 */ 133 | CLK_PERIPHERAL_TIMER1 = (uint8_t)0x07, /*!< Peripheral Clock Enable 1, Timer1 */ 134 | CLK_PERIPHERAL_AWU = (uint8_t)0x12, /*!< Peripheral Clock Enable 2, AWU */ 135 | CLK_PERIPHERAL_ADC = (uint8_t)0x13, /*!< Peripheral Clock Enable 2, ADC */ 136 | CLK_PERIPHERAL_CAN = (uint8_t)0x17 /*!< Peripheral Clock Enable 2, CAN */ 137 | } CLK_Peripheral_TypeDef; 138 | 139 | /** 140 | * @brief CLK Flags. 141 | */ 142 | /* Elements values convention: 0xXZZ 143 | X = choice between the flags registers 144 | X = 1 : ICKR 145 | X = 2 : ECKR 146 | X = 3 : SWCR 147 | X = 4 : CSSR 148 | X = 5 : CCOR 149 | ZZ = flag mask in the register (same as map file) 150 | */ 151 | typedef enum { 152 | CLK_FLAG_LSIRDY = (uint16_t)0x0110, /*!< Low speed internal oscillator ready Flag */ 153 | CLK_FLAG_HSIRDY = (uint16_t)0x0102, /*!< High speed internal oscillator ready Flag */ 154 | CLK_FLAG_HSERDY = (uint16_t)0x0202, /*!< High speed external oscillator ready Flag */ 155 | CLK_FLAG_SWIF = (uint16_t)0x0308, /*!< Clock switch interrupt Flag */ 156 | CLK_FLAG_SWBSY = (uint16_t)0x0301, /*!< Switch busy Flag */ 157 | CLK_FLAG_CSSD = (uint16_t)0x0408, /*!< Clock security system detection Flag */ 158 | CLK_FLAG_AUX = (uint16_t)0x0402, /*!< Auxiliary oscillator connected to master clock */ 159 | CLK_FLAG_CCOBSY = (uint16_t)0x0504, /*!< Configurable clock output busy */ 160 | CLK_FLAG_CCORDY = (uint16_t)0x0502 /*!< Configurable clock output ready */ 161 | }CLK_Flag_TypeDef; 162 | 163 | /** 164 | * @brief CLK interrupt configuration and Flags cleared by software. 165 | */ 166 | typedef enum { 167 | CLK_IT_CSSD = (uint8_t)0x0C, /*!< Clock security system detection Flag */ 168 | CLK_IT_SWIF = (uint8_t)0x1C /*!< Clock switch interrupt Flag */ 169 | }CLK_IT_TypeDef; 170 | 171 | /** 172 | * @brief CLK Clock Divisor. 173 | */ 174 | 175 | /* Warning: 176 | 0xxxxxx = HSI divider 177 | 1xxxxxx = CPU divider 178 | Other bits correspond to the divider's bits mapping 179 | */ 180 | typedef enum { 181 | CLK_PRESCALER_HSIDIV1 = (uint8_t)0x00, /*!< High speed internal clock prescaler: 1 */ 182 | CLK_PRESCALER_HSIDIV2 = (uint8_t)0x08, /*!< High speed internal clock prescaler: 2 */ 183 | CLK_PRESCALER_HSIDIV4 = (uint8_t)0x10, /*!< High speed internal clock prescaler: 4 */ 184 | CLK_PRESCALER_HSIDIV8 = (uint8_t)0x18, /*!< High speed internal clock prescaler: 8 */ 185 | CLK_PRESCALER_CPUDIV1 = (uint8_t)0x80, /*!< CPU clock division factors 1 */ 186 | CLK_PRESCALER_CPUDIV2 = (uint8_t)0x81, /*!< CPU clock division factors 2 */ 187 | CLK_PRESCALER_CPUDIV4 = (uint8_t)0x82, /*!< CPU clock division factors 4 */ 188 | CLK_PRESCALER_CPUDIV8 = (uint8_t)0x83, /*!< CPU clock division factors 8 */ 189 | CLK_PRESCALER_CPUDIV16 = (uint8_t)0x84, /*!< CPU clock division factors 16 */ 190 | CLK_PRESCALER_CPUDIV32 = (uint8_t)0x85, /*!< CPU clock division factors 32 */ 191 | CLK_PRESCALER_CPUDIV64 = (uint8_t)0x86, /*!< CPU clock division factors 64 */ 192 | CLK_PRESCALER_CPUDIV128 = (uint8_t)0x87 /*!< CPU clock division factors 128 */ 193 | } CLK_Prescaler_TypeDef; 194 | 195 | /** 196 | * @brief SWIM Clock divider. 197 | */ 198 | typedef enum { 199 | CLK_SWIMDIVIDER_2 = (uint8_t)0x00, /*!< SWIM clock is divided by 2 */ 200 | CLK_SWIMDIVIDER_OTHER = (uint8_t)0x01 /*!< SWIM clock is not divided by 2 */ 201 | }CLK_SWIMDivider_TypeDef; 202 | 203 | /** 204 | * @} 205 | */ 206 | 207 | /* Exported constants --------------------------------------------------------*/ 208 | 209 | /** @addtogroup CLK_Exported_Constants 210 | * @{ 211 | */ 212 | #define CLK_TIMEOUT ((uint16_t)0xFFFF) /*!< Max Timeout for the clock switch operation. */ 213 | /** 214 | * @} 215 | */ 216 | 217 | /* Private macros ------------------------------------------------------------*/ 218 | /** @addtogroup CLK_Private_Macros 219 | * @{ 220 | */ 221 | 222 | /** 223 | * @brief Macros used by the assert function in order to check the different functions parameters. 224 | */ 225 | 226 | /** 227 | * @brief Macros used by the assert function in order to check the clock switching modes. 228 | */ 229 | #define IS_CLK_SWITCHMODE_OK(MODE) (((MODE) == CLK_SWITCHMODE_MANUAL) || ((MODE) == CLK_SWITCHMODE_AUTO)) 230 | 231 | /** 232 | * @brief Macros used by the assert function in order to check the current clock state. 233 | */ 234 | #define IS_CLK_CURRENTCLOCKSTATE_OK(STATE) (((STATE) == CLK_CURRENTCLOCKSTATE_DISABLE) ||\ 235 | ((STATE) == CLK_CURRENTCLOCKSTATE_ENABLE)) 236 | 237 | /** 238 | * @brief Macros used by the assert function in order to check the CSS configuration. 239 | */ 240 | #define IS_CLK_CSSCONFIG_OK(CSSVALUE) (((CSSVALUE) == CLK_CSSCONFIG_ENABLEWITHIT) ||\ 241 | ((CSSVALUE) == CLK_CSSCONFIG_ENABLE) ||\ 242 | ((CSSVALUE) == CLK_CSSCONFIG_DISABLE)) 243 | 244 | /** 245 | * @brief Macros used by the assert function in order to check the different clock sources. 246 | */ 247 | #define IS_CLK_SOURCE_OK(SOURCE) (((SOURCE) == CLK_SOURCE_HSI) ||\ 248 | ((SOURCE) == CLK_SOURCE_LSI) ||\ 249 | ((SOURCE) == CLK_SOURCE_HSE)) 250 | 251 | /** 252 | * @brief Macros used by the assert function in order to check the different HSI trimming values. 253 | */ 254 | #define IS_CLK_HSITRIMVALUE_OK(TRIMVALUE) (((TRIMVALUE) == CLK_HSITRIMVALUE_0) ||\ 255 | ((TRIMVALUE) == CLK_HSITRIMVALUE_1) ||\ 256 | ((TRIMVALUE) == CLK_HSITRIMVALUE_2) ||\ 257 | ((TRIMVALUE) == CLK_HSITRIMVALUE_3) ||\ 258 | ((TRIMVALUE) == CLK_HSITRIMVALUE_4) ||\ 259 | ((TRIMVALUE) == CLK_HSITRIMVALUE_5) ||\ 260 | ((TRIMVALUE) == CLK_HSITRIMVALUE_6) ||\ 261 | ((TRIMVALUE) == CLK_HSITRIMVALUE_7)) 262 | 263 | /** 264 | * @brief Macros used by the assert function in order to check the different clocks to output. 265 | */ 266 | #define IS_CLK_OUTPUT_OK(OUTPUT) (((OUTPUT) == CLK_OUTPUT_HSI) ||\ 267 | ((OUTPUT) == CLK_OUTPUT_HSE) ||\ 268 | ((OUTPUT) == CLK_OUTPUT_LSI) ||\ 269 | ((OUTPUT) == CLK_OUTPUT_CPU) ||\ 270 | ((OUTPUT) == CLK_OUTPUT_CPUDIV2) ||\ 271 | ((OUTPUT) == CLK_OUTPUT_CPUDIV4) ||\ 272 | ((OUTPUT) == CLK_OUTPUT_CPUDIV8) ||\ 273 | ((OUTPUT) == CLK_OUTPUT_CPUDIV16) ||\ 274 | ((OUTPUT) == CLK_OUTPUT_CPUDIV32) ||\ 275 | ((OUTPUT) == CLK_OUTPUT_CPUDIV64) ||\ 276 | ((OUTPUT) == CLK_OUTPUT_HSIRC) ||\ 277 | ((OUTPUT) == CLK_OUTPUT_MASTER) ||\ 278 | ((OUTPUT) == CLK_OUTPUT_OTHERS)) 279 | 280 | /** 281 | * @brief Macros used by the assert function in order to check the different peripheral's clock. 282 | */ 283 | #define IS_CLK_PERIPHERAL_OK(PERIPHERAL) (((PERIPHERAL) == CLK_PERIPHERAL_I2C) ||\ 284 | ((PERIPHERAL) == CLK_PERIPHERAL_SPI) ||\ 285 | ((PERIPHERAL) == CLK_PERIPHERAL_UART3) ||\ 286 | ((PERIPHERAL) == CLK_PERIPHERAL_UART2) ||\ 287 | ((PERIPHERAL) == CLK_PERIPHERAL_UART1) ||\ 288 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER4) ||\ 289 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER2) ||\ 290 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER5) ||\ 291 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER6) ||\ 292 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER3) ||\ 293 | ((PERIPHERAL) == CLK_PERIPHERAL_TIMER1) ||\ 294 | ((PERIPHERAL) == CLK_PERIPHERAL_CAN) ||\ 295 | ((PERIPHERAL) == CLK_PERIPHERAL_ADC) ||\ 296 | ((PERIPHERAL) == CLK_PERIPHERAL_AWU)) 297 | 298 | /** 299 | * @brief Macros used by the assert function in order to check the different clock flags. 300 | */ 301 | #define IS_CLK_FLAG_OK(FLAG) (((FLAG) == CLK_FLAG_LSIRDY) ||\ 302 | ((FLAG) == CLK_FLAG_HSIRDY) ||\ 303 | ((FLAG) == CLK_FLAG_HSERDY) ||\ 304 | ((FLAG) == CLK_FLAG_SWIF) ||\ 305 | ((FLAG) == CLK_FLAG_SWBSY) ||\ 306 | ((FLAG) == CLK_FLAG_CSSD) ||\ 307 | ((FLAG) == CLK_FLAG_AUX) ||\ 308 | ((FLAG) == CLK_FLAG_CCOBSY) ||\ 309 | ((FLAG) == CLK_FLAG_CCORDY)) 310 | 311 | /** 312 | * @brief Macros used by the assert function in order to check the different clock IT pending bits. 313 | */ 314 | #define IS_CLK_IT_OK(IT) (((IT) == CLK_IT_CSSD) || ((IT) == CLK_IT_SWIF)) 315 | 316 | /** 317 | * @brief Macros used by the assert function in order to check the different HSI prescaler values. 318 | */ 319 | #define IS_CLK_HSIPRESCALER_OK(PRESCALER) (((PRESCALER) == CLK_PRESCALER_HSIDIV1) ||\ 320 | ((PRESCALER) == CLK_PRESCALER_HSIDIV2) ||\ 321 | ((PRESCALER) == CLK_PRESCALER_HSIDIV4) ||\ 322 | ((PRESCALER) == CLK_PRESCALER_HSIDIV8)) 323 | 324 | /** 325 | * @brief Macros used by the assert function in order to check the different clock prescaler values. 326 | */ 327 | #define IS_CLK_PRESCALER_OK(PRESCALER) (((PRESCALER) == CLK_PRESCALER_HSIDIV1) ||\ 328 | ((PRESCALER) == CLK_PRESCALER_HSIDIV2) ||\ 329 | ((PRESCALER) == CLK_PRESCALER_HSIDIV4) ||\ 330 | ((PRESCALER) == CLK_PRESCALER_HSIDIV8) ||\ 331 | ((PRESCALER) == CLK_PRESCALER_CPUDIV1) ||\ 332 | ((PRESCALER) == CLK_PRESCALER_CPUDIV2) ||\ 333 | ((PRESCALER) == CLK_PRESCALER_CPUDIV4) ||\ 334 | ((PRESCALER) == CLK_PRESCALER_CPUDIV8) ||\ 335 | ((PRESCALER) == CLK_PRESCALER_CPUDIV16) ||\ 336 | ((PRESCALER) == CLK_PRESCALER_CPUDIV32) ||\ 337 | ((PRESCALER) == CLK_PRESCALER_CPUDIV64) ||\ 338 | ((PRESCALER) == CLK_PRESCALER_CPUDIV128)) 339 | 340 | /** 341 | * @brief Macros used by the assert function in order to check the different SWIM dividers values. 342 | */ 343 | #define IS_CLK_SWIMDIVIDER_OK(SWIMDIVIDER) (((SWIMDIVIDER) == CLK_SWIMDIVIDER_2) || ((SWIMDIVIDER) == CLK_SWIMDIVIDER_OTHER)) 344 | 345 | /** 346 | * @} 347 | */ 348 | 349 | /** @addtogroup CLK_Exported_functions 350 | * @{ 351 | */ 352 | void CLK_DeInit(void); 353 | void CLK_HSECmd(FunctionalState NewState); 354 | void CLK_HSICmd(FunctionalState NewState); 355 | void CLK_LSICmd(FunctionalState NewState); 356 | void CLK_CCOCmd(FunctionalState NewState); 357 | void CLK_ClockSwitchCmd(FunctionalState NewState); 358 | void CLK_FastHaltWakeUpCmd(FunctionalState NewState); 359 | void CLK_SlowActiveHaltWakeUpCmd(FunctionalState NewState); 360 | void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState); 361 | ErrorStatus CLK_ClockSwitchConfig(CLK_SwitchMode_TypeDef CLK_SwitchMode, CLK_Source_TypeDef CLK_NewClock, FunctionalState ITState, CLK_CurrentClockState_TypeDef CLK_CurrentClockState); 362 | void CLK_HSIPrescalerConfig(CLK_Prescaler_TypeDef HSIPrescaler); 363 | void CLK_CCOConfig(CLK_Output_TypeDef CLK_CCO); 364 | void CLK_ITConfig(CLK_IT_TypeDef CLK_IT, FunctionalState NewState); 365 | void CLK_SYSCLKConfig(CLK_Prescaler_TypeDef CLK_Prescaler); 366 | void CLK_SWIMConfig(CLK_SWIMDivider_TypeDef CLK_SWIMDivider); 367 | void CLK_ClockSecuritySystemEnable(void); 368 | void CLK_SYSCLKEmergencyClear(void); 369 | void CLK_AdjustHSICalibrationValue(CLK_HSITrimValue_TypeDef CLK_HSICalibrationValue); 370 | uint32_t CLK_GetClockFreq(void); 371 | CLK_Source_TypeDef CLK_GetSYSCLKSource(void); 372 | FlagStatus CLK_GetFlagStatus(CLK_Flag_TypeDef CLK_FLAG); 373 | ITStatus CLK_GetITStatus(CLK_IT_TypeDef CLK_IT); 374 | void CLK_ClearITPendingBit(CLK_IT_TypeDef CLK_IT); 375 | 376 | /** 377 | * @} 378 | */ 379 | #endif /* __STM8S_CLK_H */ 380 | 381 | 382 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 383 | -------------------------------------------------------------------------------- /include/stm8s_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_exti.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the EXTI peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_EXTI_H 30 | #define __STM8S_EXTI_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup EXTI_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief EXTI Sensitivity values for PORTA to PORTE 43 | */ 44 | typedef enum { 45 | EXTI_SENSITIVITY_FALL_LOW = (uint8_t)0x00, /*!< Interrupt on Falling edge and Low level */ 46 | EXTI_SENSITIVITY_RISE_ONLY = (uint8_t)0x01, /*!< Interrupt on Rising edge only */ 47 | EXTI_SENSITIVITY_FALL_ONLY = (uint8_t)0x02, /*!< Interrupt on Falling edge only */ 48 | EXTI_SENSITIVITY_RISE_FALL = (uint8_t)0x03 /*!< Interrupt on Rising and Falling edges */ 49 | } EXTI_Sensitivity_TypeDef; 50 | 51 | /** 52 | * @brief EXTI Sensitivity values for TLI 53 | */ 54 | typedef enum { 55 | EXTI_TLISENSITIVITY_FALL_ONLY = (uint8_t)0x00, /*!< Top Level Interrupt on Falling edge only */ 56 | EXTI_TLISENSITIVITY_RISE_ONLY = (uint8_t)0x04 /*!< Top Level Interrupt on Rising edge only */ 57 | } EXTI_TLISensitivity_TypeDef; 58 | 59 | /** 60 | * @brief EXTI PortNum possible values 61 | */ 62 | typedef enum { 63 | EXTI_PORT_GPIOA = (uint8_t)0x00, /*!< GPIO Port A */ 64 | EXTI_PORT_GPIOB = (uint8_t)0x01, /*!< GPIO Port B */ 65 | EXTI_PORT_GPIOC = (uint8_t)0x02, /*!< GPIO Port C */ 66 | EXTI_PORT_GPIOD = (uint8_t)0x03, /*!< GPIO Port D */ 67 | EXTI_PORT_GPIOE = (uint8_t)0x04 /*!< GPIO Port E */ 68 | } EXTI_Port_TypeDef; 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /* Private macros ------------------------------------------------------------*/ 75 | 76 | /** @addtogroup EXTI_Private_Macros 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @brief Macro used by the assert function in order to check the different sensitivity values for PORTA to PORTE. 82 | */ 83 | #define IS_EXTI_SENSITIVITY_OK(SensitivityValue) \ 84 | (((SensitivityValue) == EXTI_SENSITIVITY_FALL_LOW) || \ 85 | ((SensitivityValue) == EXTI_SENSITIVITY_RISE_ONLY) || \ 86 | ((SensitivityValue) == EXTI_SENSITIVITY_FALL_ONLY) || \ 87 | ((SensitivityValue) == EXTI_SENSITIVITY_RISE_FALL)) 88 | 89 | /** 90 | * @brief Macro used by the assert function in order to check the different sensitivity values for TLI. 91 | */ 92 | #define IS_EXTI_TLISENSITIVITY_OK(SensitivityValue) \ 93 | (((SensitivityValue) == EXTI_TLISENSITIVITY_FALL_ONLY) || \ 94 | ((SensitivityValue) == EXTI_TLISENSITIVITY_RISE_ONLY)) 95 | 96 | /** 97 | * @brief Macro used by the assert function in order to check the different Port values 98 | */ 99 | #define IS_EXTI_PORT_OK(PORT) \ 100 | (((PORT) == EXTI_PORT_GPIOA) ||\ 101 | ((PORT) == EXTI_PORT_GPIOB) ||\ 102 | ((PORT) == EXTI_PORT_GPIOC) ||\ 103 | ((PORT) == EXTI_PORT_GPIOD) ||\ 104 | ((PORT) == EXTI_PORT_GPIOE)) 105 | 106 | /** 107 | * @brief Macro used by the assert function in order to check the different values of the EXTI PinMask 108 | */ 109 | #define IS_EXTI_PINMASK_OK(PinMask) ((((PinMask) & (uint8_t)0x00) == (uint8_t)0x00) && ((PinMask) != (uint8_t)0x00)) 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /* Exported functions ------------------------------------------------------- */ 116 | 117 | /** @addtogroup EXTI_Exported_Functions 118 | * @{ 119 | */ 120 | 121 | void EXTI_DeInit(void); 122 | void EXTI_SetExtIntSensitivity(EXTI_Port_TypeDef Port, EXTI_Sensitivity_TypeDef SensitivityValue); 123 | void EXTI_SetTLISensitivity(EXTI_TLISensitivity_TypeDef SensitivityValue); 124 | EXTI_Sensitivity_TypeDef EXTI_GetExtIntSensitivity(EXTI_Port_TypeDef Port); 125 | EXTI_TLISensitivity_TypeDef EXTI_GetTLISensitivity(void); 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | #endif /* __STM8S_EXTI_H */ 132 | 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /include/stm8s_flash.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_flash.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the FLASH peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_FLASH_H 30 | #define __STM8S_FLASH_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported constants --------------------------------------------------------*/ 36 | 37 | /** @addtogroup FLASH_Exported_Constants 38 | * @{ 39 | */ 40 | 41 | #define FLASH_PROG_START_PHYSICAL_ADDRESS ((uint32_t)0x008000) /*!< Program memory: start address */ 42 | 43 | #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 44 | #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0x027FFF) /*!< Program memory: end address */ 45 | #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)1024) /*!< Program memory: total number of blocks */ 46 | #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 47 | #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x0047FF) /*!< Data EEPROM memory: end address */ 48 | #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)16) /*!< Data EEPROM memory: total number of blocks */ 49 | #define FLASH_BLOCK_SIZE ((uint8_t)128) /*!< Number of bytes in a block (common for Program and Data memories) */ 50 | #endif /* STM8S208, STM8S207, STM8S007, STM8AF52Ax, STM8AF62Ax */ 51 | 52 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 53 | #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0xFFFF) /*!< Program memory: end address */ 54 | #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)256) /*!< Program memory: total number of blocks */ 55 | #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 56 | #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x0043FF) /*!< Data EEPROM memory: end address */ 57 | #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)8) /*!< Data EEPROM memory: total number of blocks */ 58 | #define FLASH_BLOCK_SIZE ((uint8_t)128) /*!< Number of bytes in a block (common for Program and Data memories) */ 59 | #endif /* STM8S105 or STM8AF626x */ 60 | 61 | #if defined(STM8S103) || defined(STM8S003) || defined(STM8S001) || defined(STM8S903) || defined(STM8AF622x) 62 | #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0x9FFF) /*!< Program memory: end address */ 63 | #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)128) /*!< Program memory: total number of blocks */ 64 | #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 65 | #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x00427F) /*!< Data EEPROM memory: end address */ 66 | #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)10) /*!< Data EEPROM memory: total number of blocks */ 67 | #define FLASH_BLOCK_SIZE ((uint8_t)64) /*!< Number of bytes in a block (common for Program and Data memories) */ 68 | #endif /* STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF622x*/ 69 | 70 | #define FLASH_RASS_KEY1 ((uint8_t)0x56) /*!< First RASS key */ 71 | #define FLASH_RASS_KEY2 ((uint8_t)0xAE) /*!< Second RASS key */ 72 | 73 | #define OPTION_BYTE_START_PHYSICAL_ADDRESS ((uint16_t)0x4800) 74 | #define OPTION_BYTE_END_PHYSICAL_ADDRESS ((uint16_t)0x487F) 75 | #define FLASH_OPTIONBYTE_ERROR ((uint16_t)0x5555) /*!< Error code option byte 76 | (if value read is not equal to complement value read) */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Exported types ------------------------------------------------------------*/ 82 | 83 | /** @addtogroup FLASH_Exported_Types 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief FLASH Memory types 89 | */ 90 | typedef enum { 91 | FLASH_MEMTYPE_PROG = (uint8_t)0xFD, /*!< Program memory */ 92 | FLASH_MEMTYPE_DATA = (uint8_t)0xF7 /*!< Data EEPROM memory */ 93 | } FLASH_MemType_TypeDef; 94 | 95 | /** 96 | * @brief FLASH programming modes 97 | */ 98 | typedef enum { 99 | FLASH_PROGRAMMODE_STANDARD = (uint8_t)0x00, /*!< Standard programming mode */ 100 | FLASH_PROGRAMMODE_FAST = (uint8_t)0x10 /*!< Fast programming mode */ 101 | } FLASH_ProgramMode_TypeDef; 102 | 103 | /** 104 | * @brief FLASH fixed programming time 105 | */ 106 | typedef enum { 107 | FLASH_PROGRAMTIME_STANDARD = (uint8_t)0x00, /*!< Standard programming time fixed at 1/2 tprog */ 108 | FLASH_PROGRAMTIME_TPROG = (uint8_t)0x01 /*!< Programming time fixed at tprog */ 109 | } FLASH_ProgramTime_TypeDef; 110 | 111 | /** 112 | * @brief FLASH Low Power mode select 113 | */ 114 | typedef enum { 115 | FLASH_LPMODE_POWERDOWN = (uint8_t)0x04, /*!< HALT: Power-Down / ACTIVE-HALT: Power-Down */ 116 | FLASH_LPMODE_STANDBY = (uint8_t)0x08, /*!< HALT: Standby / ACTIVE-HALT: Standby */ 117 | FLASH_LPMODE_POWERDOWN_STANDBY = (uint8_t)0x00, /*!< HALT: Power-Down / ACTIVE-HALT: Standby */ 118 | FLASH_LPMODE_STANDBY_POWERDOWN = (uint8_t)0x0C /*!< HALT: Standby / ACTIVE-HALT: Power-Down */ 119 | } 120 | FLASH_LPMode_TypeDef; 121 | 122 | /** 123 | * @brief FLASH status of the last operation 124 | */ 125 | typedef enum { 126 | #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 127 | defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 128 | FLASH_STATUS_END_HIGH_VOLTAGE = (uint8_t)0x40, /*!< End of high voltage */ 129 | #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 130 | FLASH_STATUS_SUCCESSFUL_OPERATION = (uint8_t)0x04, /*!< End of operation flag */ 131 | FLASH_STATUS_TIMEOUT = (uint8_t)0x02, /*!< Time out error */ 132 | FLASH_STATUS_WRITE_PROTECTION_ERROR = (uint8_t)0x01 /*!< Write attempted to protected page */ 133 | } FLASH_Status_TypeDef; 134 | 135 | /** 136 | * @brief FLASH flags definition 137 | * - Warning : FLAG value = mapping position register 138 | */ 139 | typedef enum { 140 | #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 141 | defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 142 | FLASH_FLAG_HVOFF = (uint8_t)0x40, /*!< End of high voltage flag */ 143 | #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 144 | FLASH_FLAG_DUL = (uint8_t)0x08, /*!< Data EEPROM unlocked flag */ 145 | FLASH_FLAG_EOP = (uint8_t)0x04, /*!< End of programming (write or erase operation) flag */ 146 | FLASH_FLAG_PUL = (uint8_t)0x02, /*!< Flash Program memory unlocked flag */ 147 | FLASH_FLAG_WR_PG_DIS = (uint8_t)0x01 /*!< Write attempted to protected page flag */ 148 | } FLASH_Flag_TypeDef; 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /* Private macros ------------------------------------------------------------*/ 155 | 156 | /** 157 | * @brief Macros used by the assert function in order to check the different functions parameters. 158 | * @addtogroup FLASH_Private_Macros 159 | * @{ 160 | */ 161 | 162 | /** 163 | * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program Address 164 | */ 165 | 166 | #define IS_FLASH_PROG_ADDRESS_OK(ADDRESS) (((ADDRESS) >= FLASH_PROG_START_PHYSICAL_ADDRESS) && \ 167 | ((ADDRESS) <= FLASH_PROG_END_PHYSICAL_ADDRESS)) 168 | 169 | /** 170 | * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom Address 171 | */ 172 | 173 | #define IS_FLASH_DATA_ADDRESS_OK(ADDRESS) (((ADDRESS) >= FLASH_DATA_START_PHYSICAL_ADDRESS) && \ 174 | ((ADDRESS) <= FLASH_DATA_END_PHYSICAL_ADDRESS)) 175 | 176 | /** 177 | * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom and flash program Address 178 | */ 179 | #define IS_FLASH_ADDRESS_OK(ADDRESS)((((ADDRESS) >= FLASH_PROG_START_PHYSICAL_ADDRESS) && ((ADDRESS) <= FLASH_PROG_END_PHYSICAL_ADDRESS)) || \ 180 | (((ADDRESS) >= FLASH_DATA_START_PHYSICAL_ADDRESS) && ((ADDRESS) <= FLASH_DATA_END_PHYSICAL_ADDRESS))) 181 | 182 | /** 183 | * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program Block number 184 | */ 185 | #define IS_FLASH_PROG_BLOCK_NUMBER_OK(BLOCKNUM) ((BLOCKNUM) < FLASH_PROG_BLOCKS_NUMBER) 186 | 187 | /** 188 | * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom Block number 189 | */ 190 | #define IS_FLASH_DATA_BLOCK_NUMBER_OK(BLOCKNUM) ((BLOCKNUM) < FLASH_DATA_BLOCKS_NUMBER) 191 | 192 | /** 193 | * @brief Macro used by the assert function in order to check the different sensitivity values for the flash memory type 194 | */ 195 | 196 | #define IS_MEMORY_TYPE_OK(MEMTYPE) (((MEMTYPE) == FLASH_MEMTYPE_PROG) || \ 197 | ((MEMTYPE) == FLASH_MEMTYPE_DATA)) 198 | 199 | /** 200 | * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program mode 201 | */ 202 | 203 | #define IS_FLASH_PROGRAM_MODE_OK(MODE) (((MODE) == FLASH_PROGRAMMODE_STANDARD) || \ 204 | ((MODE) == FLASH_PROGRAMMODE_FAST)) 205 | 206 | /** 207 | * @brief Macro used by the assert function in order to check the program time mode 208 | */ 209 | 210 | #define IS_FLASH_PROGRAM_TIME_OK(TIME) (((TIME) == FLASH_PROGRAMTIME_STANDARD) || \ 211 | ((TIME) == FLASH_PROGRAMTIME_TPROG)) 212 | 213 | /** 214 | * @brief Macro used by the assert function in order to check the different 215 | * sensitivity values for the low power mode 216 | */ 217 | 218 | #define IS_FLASH_LOW_POWER_MODE_OK(LPMODE) (((LPMODE) == FLASH_LPMODE_POWERDOWN) || \ 219 | ((LPMODE) == FLASH_LPMODE_STANDBY) || \ 220 | ((LPMODE) == FLASH_LPMODE_POWERDOWN_STANDBY) || \ 221 | ((LPMODE) == FLASH_LPMODE_STANDBY_POWERDOWN)) 222 | 223 | /** 224 | * @brief Macro used by the assert function in order to check the different 225 | * sensitivity values for the option bytes Address 226 | */ 227 | #define IS_OPTION_BYTE_ADDRESS_OK(ADDRESS) (((ADDRESS) >= OPTION_BYTE_START_PHYSICAL_ADDRESS) && \ 228 | ((ADDRESS) <= OPTION_BYTE_END_PHYSICAL_ADDRESS)) 229 | 230 | 231 | /** 232 | * @brief Macro used by the assert function in order to check the different flags values 233 | */ 234 | #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 235 | defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 236 | #define IS_FLASH_FLAGS_OK(FLAG) (((FLAG) == FLASH_FLAG_HVOFF) || \ 237 | ((FLAG) == FLASH_FLAG_DUL) || \ 238 | ((FLAG) == FLASH_FLAG_EOP) || \ 239 | ((FLAG) == FLASH_FLAG_PUL) || \ 240 | ((FLAG) == FLASH_FLAG_WR_PG_DIS)) 241 | #else /* STM8S103, STM8S001, STM8S903, STM8AF622x */ 242 | #define IS_FLASH_FLAGS_OK(FLAG) (((FLAG) == FLASH_FLAG_DUL) || \ 243 | ((FLAG) == FLASH_FLAG_EOP) || \ 244 | ((FLAG) == FLASH_FLAG_PUL) || \ 245 | ((FLAG) == FLASH_FLAG_WR_PG_DIS)) 246 | #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 247 | /** 248 | * @} 249 | */ 250 | 251 | /* Exported functions ------------------------------------------------------- */ 252 | 253 | /** @addtogroup FLASH_Exported_Functions 254 | * @{ 255 | */ 256 | void FLASH_Unlock(FLASH_MemType_TypeDef FLASH_MemType); 257 | void FLASH_Lock(FLASH_MemType_TypeDef FLASH_MemType); 258 | void FLASH_DeInit(void); 259 | void FLASH_ITConfig(FunctionalState NewState); 260 | void FLASH_EraseByte(uint32_t Address); 261 | void FLASH_ProgramByte(uint32_t Address, uint8_t Data); 262 | uint8_t FLASH_ReadByte(uint32_t Address); 263 | void FLASH_ProgramWord(uint32_t Address, uint32_t Data); 264 | uint16_t FLASH_ReadOptionByte(uint16_t Address); 265 | void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data); 266 | void FLASH_EraseOptionByte(uint16_t Address); 267 | void FLASH_SetLowPowerMode(FLASH_LPMode_TypeDef FLASH_LPMode); 268 | void FLASH_SetProgrammingTime(FLASH_ProgramTime_TypeDef FLASH_ProgTime); 269 | FLASH_LPMode_TypeDef FLASH_GetLowPowerMode(void); 270 | FLASH_ProgramTime_TypeDef FLASH_GetProgrammingTime(void); 271 | uint32_t FLASH_GetBootSize(void); 272 | FlagStatus FLASH_GetFlagStatus(FLASH_Flag_TypeDef FLASH_FLAG); 273 | 274 | /** 275 | @code 276 | All the functions declared below must be executed from RAM exclusively, except 277 | for the FLASH_WaitForLastOperation function which can be executed from Flash. 278 | 279 | Steps of the execution from RAM differs from one toolchain to another. 280 | for more details refer to stm8s_flash.c file. 281 | 282 | To enable execution from RAM you can either uncomment the following define 283 | in the stm8s.h file or define it in your toolchain compiler preprocessor 284 | - #define RAM_EXECUTION (1) 285 | 286 | @endcode 287 | */ 288 | IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType)); 289 | IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType, 290 | FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer)); 291 | IN_RAM(FLASH_Status_TypeDef FLASH_WaitForLastOperation(FLASH_MemType_TypeDef FLASH_MemType)); 292 | 293 | /** 294 | * @} 295 | */ 296 | 297 | #endif /*__STM8S_FLASH_H */ 298 | 299 | 300 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 301 | -------------------------------------------------------------------------------- /include/stm8s_gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_gpio.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the GPIO peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_GPIO_H 30 | #define __STM8S_GPIO_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported variables ------------------------------------------------------- */ 36 | /* Exported types ------------------------------------------------------------*/ 37 | 38 | /** @addtogroup GPIO_Exported_Types 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @brief GPIO modes 44 | * 45 | * Bits definitions: 46 | * - Bit 7: 0 = INPUT mode 47 | * 1 = OUTPUT mode 48 | * 1 = PULL-UP (input) or PUSH-PULL (output) 49 | * - Bit 5: 0 = No external interrupt (input) or No slope control (output) 50 | * 1 = External interrupt (input) or Slow control enabled (output) 51 | * - Bit 4: 0 = Low level (output) 52 | * 1 = High level (output push-pull) or HI-Z (output open-drain) 53 | */ 54 | typedef enum 55 | { 56 | GPIO_MODE_IN_FL_NO_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */ 57 | GPIO_MODE_IN_PU_NO_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */ 58 | GPIO_MODE_IN_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */ 59 | GPIO_MODE_IN_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */ 60 | GPIO_MODE_OUT_OD_LOW_FAST = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */ 61 | GPIO_MODE_OUT_PP_LOW_FAST = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */ 62 | GPIO_MODE_OUT_OD_LOW_SLOW = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */ 63 | GPIO_MODE_OUT_PP_LOW_SLOW = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */ 64 | GPIO_MODE_OUT_OD_HIZ_FAST = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level,10MHz */ 65 | GPIO_MODE_OUT_PP_HIGH_FAST = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */ 66 | GPIO_MODE_OUT_OD_HIZ_SLOW = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */ 67 | GPIO_MODE_OUT_PP_HIGH_SLOW = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */ 68 | }GPIO_Mode_TypeDef; 69 | 70 | /** 71 | * @brief Definition of the GPIO pins. Used by the @ref GPIO_Init function in 72 | * order to select the pins to be initialized. 73 | */ 74 | 75 | typedef enum 76 | { 77 | GPIO_PIN_0 = ((uint8_t)0x01), /*!< Pin 0 selected */ 78 | GPIO_PIN_1 = ((uint8_t)0x02), /*!< Pin 1 selected */ 79 | GPIO_PIN_2 = ((uint8_t)0x04), /*!< Pin 2 selected */ 80 | GPIO_PIN_3 = ((uint8_t)0x08), /*!< Pin 3 selected */ 81 | GPIO_PIN_4 = ((uint8_t)0x10), /*!< Pin 4 selected */ 82 | GPIO_PIN_5 = ((uint8_t)0x20), /*!< Pin 5 selected */ 83 | GPIO_PIN_6 = ((uint8_t)0x40), /*!< Pin 6 selected */ 84 | GPIO_PIN_7 = ((uint8_t)0x80), /*!< Pin 7 selected */ 85 | GPIO_PIN_LNIB = ((uint8_t)0x0F), /*!< Low nibble pins selected */ 86 | GPIO_PIN_HNIB = ((uint8_t)0xF0), /*!< High nibble pins selected */ 87 | GPIO_PIN_ALL = ((uint8_t)0xFF) /*!< All pins selected */ 88 | }GPIO_Pin_TypeDef; 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /* Exported constants --------------------------------------------------------*/ 95 | /* Exported macros -----------------------------------------------------------*/ 96 | /* Private macros ------------------------------------------------------------*/ 97 | 98 | /** @addtogroup GPIO_Private_Macros 99 | * @{ 100 | */ 101 | 102 | /** 103 | * @brief Macro used by the assert function to check the different functions parameters. 104 | */ 105 | 106 | /** 107 | * @brief Macro used by the assert function in order to check the different 108 | * values of GPIOMode_TypeDef. 109 | */ 110 | #define IS_GPIO_MODE_OK(MODE) \ 111 | (((MODE) == GPIO_MODE_IN_FL_NO_IT) || \ 112 | ((MODE) == GPIO_MODE_IN_PU_NO_IT) || \ 113 | ((MODE) == GPIO_MODE_IN_FL_IT) || \ 114 | ((MODE) == GPIO_MODE_IN_PU_IT) || \ 115 | ((MODE) == GPIO_MODE_OUT_OD_LOW_FAST) || \ 116 | ((MODE) == GPIO_MODE_OUT_PP_LOW_FAST) || \ 117 | ((MODE) == GPIO_MODE_OUT_OD_LOW_SLOW) || \ 118 | ((MODE) == GPIO_MODE_OUT_PP_LOW_SLOW) || \ 119 | ((MODE) == GPIO_MODE_OUT_OD_HIZ_FAST) || \ 120 | ((MODE) == GPIO_MODE_OUT_PP_HIGH_FAST) || \ 121 | ((MODE) == GPIO_MODE_OUT_OD_HIZ_SLOW) || \ 122 | ((MODE) == GPIO_MODE_OUT_PP_HIGH_SLOW)) 123 | 124 | /** 125 | * @brief Macro used by the assert function in order to check the different 126 | * values of GPIO_Pins. 127 | */ 128 | #define IS_GPIO_PIN_OK(PIN) ((PIN) != (uint8_t)0x00) 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /* Exported functions ------------------------------------------------------- */ 135 | /** @addtogroup GPIO_Exported_Functions 136 | * @{ 137 | */ 138 | 139 | void GPIO_DeInit(GPIO_TypeDef* GPIOx); 140 | void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode); 141 | void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal); 142 | void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 143 | void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 144 | void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins); 145 | uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx); 146 | uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx); 147 | BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin); 148 | void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState); 149 | /** 150 | * @} 151 | */ 152 | 153 | #endif /* __STM8L_GPIO_H */ 154 | 155 | 156 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /include/stm8s_itc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_itc.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the ITC peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_ITC_H 30 | #define __STM8S_ITC_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /* Exported types ------------------------------------------------------------*/ 36 | 37 | /** @addtogroup ITC_Exported_Types 38 | * @{ 39 | */ 40 | 41 | /** 42 | * @brief ITC Interrupt Lines selection 43 | */ 44 | typedef enum { 45 | ITC_IRQ_TLI = (uint8_t)0, /*!< Software interrupt */ 46 | ITC_IRQ_AWU = (uint8_t)1, /*!< Auto wake up from halt interrupt */ 47 | ITC_IRQ_CLK = (uint8_t)2, /*!< Clock controller interrupt */ 48 | ITC_IRQ_PORTA = (uint8_t)3, /*!< Port A external interrupts */ 49 | ITC_IRQ_PORTB = (uint8_t)4, /*!< Port B external interrupts */ 50 | ITC_IRQ_PORTC = (uint8_t)5, /*!< Port C external interrupts */ 51 | ITC_IRQ_PORTD = (uint8_t)6, /*!< Port D external interrupts */ 52 | ITC_IRQ_PORTE = (uint8_t)7, /*!< Port E external interrupts */ 53 | 54 | #if defined(STM8S208) || defined(STM8AF52Ax) 55 | ITC_IRQ_CAN_RX = (uint8_t)8, /*!< beCAN RX interrupt */ 56 | ITC_IRQ_CAN_TX = (uint8_t)9, /*!< beCAN TX/ER/SC interrupt */ 57 | #endif /*STM8S208 or STM8AF52Ax */ 58 | 59 | #if defined(STM8S903) || defined(STM8AF622x) 60 | ITC_IRQ_PORTF = (uint8_t)8, /*!< Port F external interrupts */ 61 | #endif /*STM8S903 or STM8AF622x */ 62 | 63 | ITC_IRQ_SPI = (uint8_t)10, /*!< SPI interrupt */ 64 | ITC_IRQ_TIM1_OVF = (uint8_t)11, /*!< TIM1 update/overflow/underflow/trigger/ 65 | break interrupt*/ 66 | ITC_IRQ_TIM1_CAPCOM = (uint8_t)12, /*!< TIM1 capture/compare interrupt */ 67 | 68 | #if defined(STM8S903) || defined(STM8AF622x) 69 | ITC_IRQ_TIM5_OVFTRI = (uint8_t)13, /*!< TIM5 update/overflow/underflow/trigger/ 70 | interrupt */ 71 | ITC_IRQ_TIM5_CAPCOM = (uint8_t)14, /*!< TIM5 capture/compare interrupt */ 72 | #else 73 | ITC_IRQ_TIM2_OVF = (uint8_t)13, /*!< TIM2 update /overflow interrupt */ 74 | ITC_IRQ_TIM2_CAPCOM = (uint8_t)14, /*!< TIM2 capture/compare interrupt */ 75 | #endif /*STM8S903 or STM8AF622x */ 76 | 77 | ITC_IRQ_TIM3_OVF = (uint8_t)15, /*!< TIM3 update /overflow interrupt*/ 78 | ITC_IRQ_TIM3_CAPCOM = (uint8_t)16, /*!< TIM3 update /overflow interrupt */ 79 | 80 | #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \ 81 | defined(STM8S003) || defined(STM8S001) ||defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 82 | ITC_IRQ_UART1_TX = (uint8_t)17, /*!< UART1 TX interrupt */ 83 | ITC_IRQ_UART1_RX = (uint8_t)18, /*!< UART1 RX interrupt */ 84 | #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */ 85 | #if defined(STM8AF622x) 86 | ITC_IRQ_UART4_TX = (uint8_t)17, /*!< UART4 TX interrupt */ 87 | ITC_IRQ_UART4_RX = (uint8_t)18, /*!< UART4 RX interrupt */ 88 | #endif /*STM8AF622x */ 89 | 90 | ITC_IRQ_I2C = (uint8_t)19, /*!< I2C interrupt */ 91 | 92 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 93 | ITC_IRQ_UART2_TX = (uint8_t)20, /*!< USART2 TX interrupt */ 94 | ITC_IRQ_UART2_RX = (uint8_t)21, /*!< USART2 RX interrupt */ 95 | #endif /*STM8S105 or STM8AF626x */ 96 | 97 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || defined(STM8AF62Ax) 98 | ITC_IRQ_UART3_TX = (uint8_t)20, /*!< USART3 TX interrupt */ 99 | ITC_IRQ_UART3_RX = (uint8_t)21, /*!< USART3 RX interrupt */ 100 | ITC_IRQ_ADC2 = (uint8_t)22, /*!< ADC2 interrupt */ 101 | #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */ 102 | 103 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x) 104 | ITC_IRQ_ADC1 = (uint8_t)22, /*!< ADC1 interrupt */ 105 | #endif /*STM8S105 or STM8S005 or STM8S003 or STM8S103 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */ 106 | 107 | #if defined(STM8S903) || defined(STM8AF622x) 108 | ITC_IRQ_TIM6_OVFTRI = (uint8_t)23, /*!< TIM6 update/overflow/underflow/trigger/ 109 | interrupt */ 110 | #else 111 | ITC_IRQ_TIM4_OVF = (uint8_t)23, /*!< TIM4 update /overflow interrupt */ 112 | #endif /*STM8S903 or STM8AF622x */ 113 | 114 | ITC_IRQ_EEPROM_EEC = (uint8_t)24 /*!< Flash interrupt */ 115 | } ITC_Irq_TypeDef; 116 | 117 | /** 118 | * @brief ITC Priority Levels selection 119 | */ 120 | typedef enum { 121 | ITC_PRIORITYLEVEL_0 = (uint8_t)0x02, /*!< Software priority level 0 (cannot be written) */ 122 | ITC_PRIORITYLEVEL_1 = (uint8_t)0x01, /*!< Software priority level 1 */ 123 | ITC_PRIORITYLEVEL_2 = (uint8_t)0x00, /*!< Software priority level 2 */ 124 | ITC_PRIORITYLEVEL_3 = (uint8_t)0x03 /*!< Software priority level 3 */ 125 | } ITC_PriorityLevel_TypeDef; 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /* Exported constants --------------------------------------------------------*/ 132 | 133 | /** @addtogroup ITC_Exported_Constants 134 | * @{ 135 | */ 136 | #define CPU_SOFT_INT_DISABLED ((uint8_t)0x28) /*!< Mask for I1 and I0 bits in CPU_CC register */ 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /* Private macros ------------------------------------------------------------*/ 143 | 144 | /** 145 | * @brief Macros used by the assert function in order to check the different functions parameters. 146 | * @addtogroup ITC_Private_Macros 147 | * @{ 148 | */ 149 | 150 | /* Used by assert function */ 151 | #define IS_ITC_IRQ_OK(IRQ) ((IRQ) <= (uint8_t)24) 152 | 153 | /* Used by assert function */ 154 | #define IS_ITC_PRIORITY_OK(PriorityValue) \ 155 | (((PriorityValue) == ITC_PRIORITYLEVEL_0) || \ 156 | ((PriorityValue) == ITC_PRIORITYLEVEL_1) || \ 157 | ((PriorityValue) == ITC_PRIORITYLEVEL_2) || \ 158 | ((PriorityValue) == ITC_PRIORITYLEVEL_3)) 159 | 160 | /* Used by assert function */ 161 | #define IS_ITC_INTERRUPTS_DISABLED (ITC_GetSoftIntStatus() == CPU_SOFT_INT_DISABLED) 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /* Exported functions ------------------------------------------------------- */ 168 | 169 | /** @addtogroup ITC_Exported_Functions 170 | * @{ 171 | */ 172 | 173 | uint8_t ITC_GetCPUCC(void); 174 | void ITC_DeInit(void); 175 | uint8_t ITC_GetSoftIntStatus(void); 176 | void ITC_SetSoftwarePriority(ITC_Irq_TypeDef IrqNum, ITC_PriorityLevel_TypeDef PriorityValue); 177 | ITC_PriorityLevel_TypeDef ITC_GetSoftwarePriority(ITC_Irq_TypeDef IrqNum); 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | #endif /* __STM8S_ITC_H */ 184 | 185 | 186 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 187 | -------------------------------------------------------------------------------- /include/stm8s_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_iwdg.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototypes and macros for the IWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_IWDG_H 30 | #define __STM8S_IWDG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup IWDG_Private_Define 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @brief Define used to prevent watchdog reset 45 | */ 46 | #define IWDG_KEY_REFRESH ((uint8_t)0xAA) /*!< This value written in the Key register prevent the watchdog reset */ 47 | 48 | /** 49 | * @brief Define used to start the watchdog counter down 50 | */ 51 | #define IWDG_KEY_ENABLE ((uint8_t)0xCC) /*!< This value written in the Key register start the watchdog counting down*/ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @addtogroup IWDG_Private_Macros 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @brief Macro used by the assert function in order to check the different 63 | * values of the prescaler. 64 | */ 65 | #define IS_IWDG_PRESCALER_OK(VALUE) (((VALUE) == IWDG_Prescaler_4 ) || \ 66 | ((VALUE) == IWDG_Prescaler_8 ) || \ 67 | ((VALUE) == IWDG_Prescaler_16 ) || \ 68 | ((VALUE) == IWDG_Prescaler_32 ) || \ 69 | ((VALUE) == IWDG_Prescaler_64 ) || \ 70 | ((VALUE) == IWDG_Prescaler_128 ) || \ 71 | ((VALUE) == IWDG_Prescaler_256)) 72 | 73 | /** 74 | * @brief Macro used by the assert function in order to check the different 75 | * values of the counter register. 76 | */ 77 | #define IS_IWDG_WRITEACCESS_MODE_OK(MODE) (((MODE) == IWDG_WriteAccess_Enable) || ((MODE) == IWDG_WriteAccess_Disable)) 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup IWDG_Exported_Types 84 | * @{ 85 | */ 86 | 87 | /** IWDG write access enumeration */ 88 | typedef enum 89 | { 90 | IWDG_WriteAccess_Enable = (uint8_t)0x55, /*!< Code 0x55 in Key register, allow write access to Prescaler and Reload registers */ 91 | IWDG_WriteAccess_Disable = (uint8_t)0x00 /*!< Code 0x00 in Key register, not allow write access to Prescaler and Reload registers */ 92 | } IWDG_WriteAccess_TypeDef; 93 | 94 | /** IWDG prescaler enumaration */ 95 | typedef enum 96 | { 97 | IWDG_Prescaler_4 = (uint8_t)0x00, /*!< Used to set prescaler register to 4 */ 98 | IWDG_Prescaler_8 = (uint8_t)0x01, /*!< Used to set prescaler register to 8 */ 99 | IWDG_Prescaler_16 = (uint8_t)0x02, /*!< Used to set prescaler register to 16 */ 100 | IWDG_Prescaler_32 = (uint8_t)0x03, /*!< Used to set prescaler register to 32 */ 101 | IWDG_Prescaler_64 = (uint8_t)0x04, /*!< Used to set prescaler register to 64 */ 102 | IWDG_Prescaler_128 = (uint8_t)0x05, /*!< Used to set prescaler register to 128 */ 103 | IWDG_Prescaler_256 = (uint8_t)0x06 /*!< Used to set prescaler register to 256 */ 104 | } IWDG_Prescaler_TypeDef; 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** @addtogroup IWDG_Exported_Functions 111 | * @{ 112 | */ 113 | 114 | void IWDG_WriteAccessCmd(IWDG_WriteAccess_TypeDef IWDG_WriteAccess); 115 | void IWDG_SetPrescaler(IWDG_Prescaler_TypeDef IWDG_Prescaler); 116 | void IWDG_SetReload(uint8_t IWDG_Reload); 117 | void IWDG_ReloadCounter(void); 118 | void IWDG_Enable(void); 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | #endif /* __STM8S_IWDG_H */ 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /include/stm8s_rst.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_rst.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the RST peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __STM8S_RST_H 29 | #define __STM8S_RST_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm8s.h" 33 | 34 | /** @addtogroup STM8S_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RST_Exported_Types 39 | * @{ 40 | */ 41 | typedef enum { 42 | RST_FLAG_EMCF = (uint8_t)0x10, /*!< EMC reset flag */ 43 | RST_FLAG_SWIMF = (uint8_t)0x08, /*!< SWIM reset flag */ 44 | RST_FLAG_ILLOPF = (uint8_t)0x04, /*!< Illigal opcode reset flag */ 45 | RST_FLAG_IWDGF = (uint8_t)0x02, /*!< Independent watchdog reset flag */ 46 | RST_FLAG_WWDGF = (uint8_t)0x01 /*!< Window watchdog reset flag */ 47 | }RST_Flag_TypeDef; 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Exported macros -----------------------------------------------------------*/ 55 | 56 | /** @addtogroup RST_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @brief Macro used by the assert function to check the different functions parameters. 62 | */ 63 | /** 64 | * @brief Macro used by the assert function to check the different RST flags. 65 | */ 66 | #define IS_RST_FLAG_OK(FLAG) (((FLAG) == RST_FLAG_EMCF) || \ 67 | ((FLAG) == RST_FLAG_SWIMF) ||\ 68 | ((FLAG) == RST_FLAG_ILLOPF) ||\ 69 | ((FLAG) == RST_FLAG_IWDGF) ||\ 70 | ((FLAG) == RST_FLAG_WWDGF)) 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @addtogroup RST_Exported_functions 77 | * @{ 78 | */ 79 | FlagStatus RST_GetFlagStatus(RST_Flag_TypeDef RST_Flag); 80 | void RST_ClearFlag(RST_Flag_TypeDef RST_Flag); 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | #endif /* __STM8S_RST_H */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /include/stm8s_spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_spi.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the SPI peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_SPI_H 30 | #define __STM8S_SPI_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /** @addtogroup SPI_Exported_Types 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @brief SPI data direction mode 45 | * Warning: element values correspond to BDM, BDOE, RXONLY bits position 46 | */ 47 | typedef enum { 48 | SPI_DATADIRECTION_2LINES_FULLDUPLEX = (uint8_t)0x00, /*!< 2-line uni-directional data mode enable */ 49 | SPI_DATADIRECTION_2LINES_RXONLY = (uint8_t)0x04, /*!< Receiver only in 2 line uni-directional data mode */ 50 | SPI_DATADIRECTION_1LINE_RX = (uint8_t)0x80, /*!< Receiver only in 1 line bi-directional data mode */ 51 | SPI_DATADIRECTION_1LINE_TX = (uint8_t)0xC0 /*!< Transmit only in 1 line bi-directional data mode */ 52 | } SPI_DataDirection_TypeDef; 53 | 54 | /** 55 | * @brief SPI Slave Select management 56 | * Warning: element values correspond to LSBFIRST bit position 57 | */ 58 | typedef enum 59 | { 60 | SPI_NSS_SOFT = (uint8_t)0x02, /*!< Software slave management disabled */ 61 | SPI_NSS_HARD = (uint8_t)0x00 /*!< Software slave management enabled */ 62 | } SPI_NSS_TypeDef; 63 | 64 | 65 | /** 66 | * @brief SPI direction transmit/receive 67 | */ 68 | 69 | typedef enum { 70 | SPI_DIRECTION_RX = (uint8_t)0x00, /*!< Selects Rx receive direction in bi-directional mode */ 71 | SPI_DIRECTION_TX = (uint8_t)0x01 /*!< Selects Tx transmission direction in bi-directional mode */ 72 | } SPI_Direction_TypeDef; 73 | 74 | /** 75 | * @brief SPI master/slave mode 76 | * Warning: element values correspond to MSTR bit position 77 | */ 78 | typedef enum { 79 | SPI_MODE_MASTER = (uint8_t)0x04, /*!< SPI Master configuration */ 80 | SPI_MODE_SLAVE = (uint8_t)0x00 /*!< SPI Slave configuration */ 81 | } SPI_Mode_TypeDef; 82 | 83 | /** 84 | * @brief SPI BaudRate Prescaler 85 | * Warning: element values correspond to BR bits position 86 | */ 87 | typedef enum { 88 | SPI_BAUDRATEPRESCALER_2 = (uint8_t)0x00, /*!< SPI frequency = frequency(CPU)/2 */ 89 | SPI_BAUDRATEPRESCALER_4 = (uint8_t)0x08, /*!< SPI frequency = frequency(CPU)/4 */ 90 | SPI_BAUDRATEPRESCALER_8 = (uint8_t)0x10, /*!< SPI frequency = frequency(CPU)/8 */ 91 | SPI_BAUDRATEPRESCALER_16 = (uint8_t)0x18, /*!< SPI frequency = frequency(CPU)/16 */ 92 | SPI_BAUDRATEPRESCALER_32 = (uint8_t)0x20, /*!< SPI frequency = frequency(CPU)/32 */ 93 | SPI_BAUDRATEPRESCALER_64 = (uint8_t)0x28, /*!< SPI frequency = frequency(CPU)/64 */ 94 | SPI_BAUDRATEPRESCALER_128 = (uint8_t)0x30, /*!< SPI frequency = frequency(CPU)/128 */ 95 | SPI_BAUDRATEPRESCALER_256 = (uint8_t)0x38 /*!< SPI frequency = frequency(CPU)/256 */ 96 | } SPI_BaudRatePrescaler_TypeDef; 97 | 98 | /** 99 | * @brief SPI Clock Polarity 100 | * Warning: element values correspond to CPOL bit position 101 | */ 102 | typedef enum { 103 | SPI_CLOCKPOLARITY_LOW = (uint8_t)0x00, /*!< Clock to 0 when idle */ 104 | SPI_CLOCKPOLARITY_HIGH = (uint8_t)0x02 /*!< Clock to 1 when idle */ 105 | } SPI_ClockPolarity_TypeDef; 106 | 107 | /** 108 | * @brief SPI Clock Phase 109 | * Warning: element values correspond to CPHA bit position 110 | */ 111 | typedef enum { 112 | SPI_CLOCKPHASE_1EDGE = (uint8_t)0x00, /*!< The first clock transition is the first data capture edge */ 113 | SPI_CLOCKPHASE_2EDGE = (uint8_t)0x01 /*!< The second clock transition is the first data capture edge */ 114 | } SPI_ClockPhase_TypeDef; 115 | 116 | /** 117 | * @brief SPI Frame Format: MSB or LSB transmitted first 118 | * Warning: element values correspond to LSBFIRST bit position 119 | */ 120 | typedef enum { 121 | SPI_FIRSTBIT_MSB = (uint8_t)0x00, /*!< MSB bit will be transmitted first */ 122 | SPI_FIRSTBIT_LSB = (uint8_t)0x80 /*!< LSB bit will be transmitted first */ 123 | } SPI_FirstBit_TypeDef; 124 | 125 | /** 126 | * @brief SPI CRC Transmit/Receive 127 | */ 128 | typedef enum { 129 | SPI_CRC_RX = (uint8_t)0x00, /*!< Select Tx CRC register */ 130 | SPI_CRC_TX = (uint8_t)0x01 /*!< Select Rx CRC register */ 131 | } SPI_CRC_TypeDef; 132 | 133 | /** 134 | * @brief SPI flags definition - Warning : FLAG value = mapping position register 135 | */ 136 | typedef enum { 137 | SPI_FLAG_BSY = (uint8_t)0x80, /*!< Busy flag */ 138 | SPI_FLAG_OVR = (uint8_t)0x40, /*!< Overrun flag */ 139 | SPI_FLAG_MODF = (uint8_t)0x20, /*!< Mode fault */ 140 | SPI_FLAG_CRCERR = (uint8_t)0x10, /*!< CRC error flag */ 141 | SPI_FLAG_WKUP = (uint8_t)0x08, /*!< Wake-up flag */ 142 | SPI_FLAG_TXE = (uint8_t)0x02, /*!< Transmit buffer empty */ 143 | SPI_FLAG_RXNE = (uint8_t)0x01 /*!< Receive buffer empty */ 144 | } SPI_Flag_TypeDef; 145 | 146 | /** 147 | * @brief SPI_IT possible values 148 | * Elements values convention: 0xYX 149 | * X: Position of the corresponding Interrupt 150 | * Y: ITPENDINGBIT position 151 | */ 152 | typedef enum 153 | { 154 | SPI_IT_WKUP = (uint8_t)0x34, /*!< Wake-up interrupt*/ 155 | SPI_IT_OVR = (uint8_t)0x65, /*!< Overrun interrupt*/ 156 | SPI_IT_MODF = (uint8_t)0x55, /*!< Mode fault interrupt*/ 157 | SPI_IT_CRCERR = (uint8_t)0x45, /*!< CRC error interrupt*/ 158 | SPI_IT_TXE = (uint8_t)0x17, /*!< Transmit buffer empty interrupt*/ 159 | SPI_IT_RXNE = (uint8_t)0x06, /*!< Receive buffer not empty interrupt*/ 160 | SPI_IT_ERR = (uint8_t)0x05 /*!< Error interrupt*/ 161 | } SPI_IT_TypeDef; 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /* Private define ------------------------------------------------------------*/ 168 | 169 | /** @addtogroup SPI_Private_Macros 170 | * @brief Macros used by the assert_param function to check the different functions parameters. 171 | * @{ 172 | */ 173 | 174 | /** 175 | * @brief Macro used by the assert_param function in order to check the data direction mode values 176 | */ 177 | #define IS_SPI_DATA_DIRECTION_OK(MODE) (((MODE) == SPI_DATADIRECTION_2LINES_FULLDUPLEX) || \ 178 | ((MODE) == SPI_DATADIRECTION_2LINES_RXONLY) || \ 179 | ((MODE) == SPI_DATADIRECTION_1LINE_RX) || \ 180 | ((MODE) == SPI_DATADIRECTION_1LINE_TX)) 181 | 182 | /** 183 | * @brief Macro used by the assert_param function in order to check the mode 184 | * half duplex data direction values 185 | */ 186 | #define IS_SPI_DIRECTION_OK(DIRECTION) (((DIRECTION) == SPI_DIRECTION_RX) || \ 187 | ((DIRECTION) == SPI_DIRECTION_TX)) 188 | 189 | /** 190 | * @brief Macro used by the assert_param function in order to check the NSS 191 | * management values 192 | */ 193 | #define IS_SPI_SLAVEMANAGEMENT_OK(NSS) (((NSS) == SPI_NSS_SOFT) || \ 194 | ((NSS) == SPI_NSS_HARD)) 195 | 196 | 197 | /** 198 | * @brief Macro used by the assert_param function in order to check the different 199 | * sensitivity values for the CRC polynomial 200 | */ 201 | #define IS_SPI_CRC_POLYNOMIAL_OK(POLYNOMIAL) ((POLYNOMIAL) > (uint8_t)0x00) 202 | 203 | /** 204 | * @brief Macro used by the assert_param function in order to check the SPI Mode values 205 | */ 206 | #define IS_SPI_MODE_OK(MODE) (((MODE) == SPI_MODE_MASTER) || \ 207 | ((MODE) == SPI_MODE_SLAVE)) 208 | 209 | /** 210 | * @brief Macro used by the assert_param function in order to check the baudrate values 211 | */ 212 | #define IS_SPI_BAUDRATE_PRESCALER_OK(PRESCALER) (((PRESCALER) == SPI_BAUDRATEPRESCALER_2) || \ 213 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_4) || \ 214 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_8) || \ 215 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_16) || \ 216 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_32) || \ 217 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_64) || \ 218 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_128) || \ 219 | ((PRESCALER) == SPI_BAUDRATEPRESCALER_256)) 220 | 221 | /** 222 | * @brief Macro used by the assert_param function in order to check the polarity values 223 | */ 224 | #define IS_SPI_POLARITY_OK(CLKPOL) (((CLKPOL) == SPI_CLOCKPOLARITY_LOW) || \ 225 | ((CLKPOL) == SPI_CLOCKPOLARITY_HIGH)) 226 | 227 | /** 228 | * @brief Macro used by the assert_param function in order to check the phase values 229 | */ 230 | #define IS_SPI_PHASE_OK(CLKPHA) (((CLKPHA) == SPI_CLOCKPHASE_1EDGE) || \ 231 | ((CLKPHA) == SPI_CLOCKPHASE_2EDGE)) 232 | 233 | /** 234 | * @brief Macro used by the assert_param function in order to check the first 235 | * bit to be transmited values 236 | */ 237 | #define IS_SPI_FIRSTBIT_OK(BIT) (((BIT) == SPI_FIRSTBIT_MSB) || \ 238 | ((BIT) == SPI_FIRSTBIT_LSB)) 239 | 240 | /** 241 | * @brief Macro used by the assert_param function in order to check the CRC 242 | * Transmit/Receive 243 | */ 244 | #define IS_SPI_CRC_OK(CRC) (((CRC) == SPI_CRC_TX) || \ 245 | ((CRC) == SPI_CRC_RX)) 246 | 247 | /** 248 | * @brief Macro used by the assert_param function in order to check the 249 | * different flags values 250 | */ 251 | #define IS_SPI_FLAGS_OK(FLAG) (((FLAG) == SPI_FLAG_OVR) || \ 252 | ((FLAG) == SPI_FLAG_MODF) || \ 253 | ((FLAG) == SPI_FLAG_CRCERR) || \ 254 | ((FLAG) == SPI_FLAG_WKUP) || \ 255 | ((FLAG) == SPI_FLAG_TXE) || \ 256 | ((FLAG) == SPI_FLAG_RXNE) || \ 257 | ((FLAG) == SPI_FLAG_BSY)) 258 | 259 | /** 260 | * @brief Macro used by the assert_param function in order to check the 261 | * different sensitivity values for the flag that can be cleared 262 | * by writing 0 263 | */ 264 | #define IS_SPI_CLEAR_FLAGS_OK(FLAG) (((FLAG) == SPI_FLAG_CRCERR) || \ 265 | ((FLAG) == SPI_FLAG_WKUP)) 266 | 267 | /** 268 | * @brief Macro used by the assert_param function in order to check the 269 | * different sensitivity values for the Interrupts 270 | */ 271 | #define IS_SPI_CONFIG_IT_OK(Interrupt) (((Interrupt) == SPI_IT_TXE) || \ 272 | ((Interrupt) == SPI_IT_RXNE) || \ 273 | ((Interrupt) == SPI_IT_ERR) || \ 274 | ((Interrupt) == SPI_IT_WKUP)) 275 | 276 | /** 277 | * @brief Macro used by the assert_param function in order to check the 278 | * different sensitivity values for the pending bit 279 | */ 280 | #define IS_SPI_GET_IT_OK(ITPendingBit) (((ITPendingBit) == SPI_IT_OVR) || \ 281 | ((ITPendingBit) == SPI_IT_MODF) || \ 282 | ((ITPendingBit) == SPI_IT_CRCERR) || \ 283 | ((ITPendingBit) == SPI_IT_WKUP) || \ 284 | ((ITPendingBit) == SPI_IT_TXE) || \ 285 | ((ITPendingBit) == SPI_IT_RXNE)) 286 | 287 | /** 288 | * @brief Macro used by the assert_param function in order to check the 289 | * different sensitivity values for the pending bit that can be cleared 290 | * by writing 0 291 | */ 292 | #define IS_SPI_CLEAR_IT_OK(ITPendingBit) (((ITPendingBit) == SPI_IT_CRCERR) || \ 293 | ((ITPendingBit) == SPI_IT_WKUP)) 294 | 295 | /** 296 | * @} 297 | */ 298 | 299 | /** @addtogroup SPI_Exported_Functions 300 | * @{ 301 | */ 302 | void SPI_DeInit(void); 303 | void SPI_Init(SPI_FirstBit_TypeDef FirstBit, 304 | SPI_BaudRatePrescaler_TypeDef BaudRatePrescaler, 305 | SPI_Mode_TypeDef Mode, SPI_ClockPolarity_TypeDef ClockPolarity, 306 | SPI_ClockPhase_TypeDef ClockPhase, 307 | SPI_DataDirection_TypeDef Data_Direction, 308 | SPI_NSS_TypeDef Slave_Management, uint8_t CRCPolynomial); 309 | void SPI_Cmd(FunctionalState NewState); 310 | void SPI_ITConfig(SPI_IT_TypeDef SPI_IT, FunctionalState NewState); 311 | void SPI_SendData(uint8_t Data); 312 | uint8_t SPI_ReceiveData(void); 313 | void SPI_NSSInternalSoftwareCmd(FunctionalState NewState); 314 | void SPI_TransmitCRC(void); 315 | void SPI_CalculateCRCCmd(FunctionalState NewState); 316 | uint8_t SPI_GetCRC(SPI_CRC_TypeDef SPI_CRC); 317 | void SPI_ResetCRC(void); 318 | uint8_t SPI_GetCRCPolynomial(void); 319 | void SPI_BiDirectionalLineConfig(SPI_Direction_TypeDef SPI_Direction); 320 | FlagStatus SPI_GetFlagStatus(SPI_Flag_TypeDef SPI_FLAG); 321 | void SPI_ClearFlag(SPI_Flag_TypeDef SPI_FLAG); 322 | ITStatus SPI_GetITStatus(SPI_IT_TypeDef SPI_IT); 323 | void SPI_ClearITPendingBit(SPI_IT_TypeDef SPI_IT); 324 | 325 | /** 326 | * @} 327 | */ 328 | 329 | #endif /* __STM8S_SPI_H */ 330 | 331 | /** 332 | * @} 333 | */ 334 | 335 | 336 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 337 | -------------------------------------------------------------------------------- /include/stm8s_tim2.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim2.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM2 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM2_H 30 | #define __STM8S_TIM2_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | 42 | /** TIM2 Forced Action */ 43 | typedef enum 44 | { 45 | TIM2_FORCEDACTION_ACTIVE = ((uint8_t)0x50), 46 | TIM2_FORCEDACTION_INACTIVE = ((uint8_t)0x40) 47 | }TIM2_ForcedAction_TypeDef; 48 | 49 | #define IS_TIM2_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM2_FORCEDACTION_ACTIVE) || \ 50 | ((ACTION) == TIM2_FORCEDACTION_INACTIVE)) 51 | 52 | /** TIM2 Prescaler */ 53 | typedef enum 54 | { 55 | TIM2_PRESCALER_1 = ((uint8_t)0x00), 56 | TIM2_PRESCALER_2 = ((uint8_t)0x01), 57 | TIM2_PRESCALER_4 = ((uint8_t)0x02), 58 | TIM2_PRESCALER_8 = ((uint8_t)0x03), 59 | TIM2_PRESCALER_16 = ((uint8_t)0x04), 60 | TIM2_PRESCALER_32 = ((uint8_t)0x05), 61 | TIM2_PRESCALER_64 = ((uint8_t)0x06), 62 | TIM2_PRESCALER_128 = ((uint8_t)0x07), 63 | TIM2_PRESCALER_256 = ((uint8_t)0x08), 64 | TIM2_PRESCALER_512 = ((uint8_t)0x09), 65 | TIM2_PRESCALER_1024 = ((uint8_t)0x0A), 66 | TIM2_PRESCALER_2048 = ((uint8_t)0x0B), 67 | TIM2_PRESCALER_4096 = ((uint8_t)0x0C), 68 | TIM2_PRESCALER_8192 = ((uint8_t)0x0D), 69 | TIM2_PRESCALER_16384 = ((uint8_t)0x0E), 70 | TIM2_PRESCALER_32768 = ((uint8_t)0x0F) 71 | }TIM2_Prescaler_TypeDef; 72 | 73 | #define IS_TIM2_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_PRESCALER_1 ) || \ 74 | ((PRESCALER) == TIM2_PRESCALER_2 ) || \ 75 | ((PRESCALER) == TIM2_PRESCALER_4 ) || \ 76 | ((PRESCALER) == TIM2_PRESCALER_8 ) || \ 77 | ((PRESCALER) == TIM2_PRESCALER_16 ) || \ 78 | ((PRESCALER) == TIM2_PRESCALER_32 ) || \ 79 | ((PRESCALER) == TIM2_PRESCALER_64 ) || \ 80 | ((PRESCALER) == TIM2_PRESCALER_128 ) || \ 81 | ((PRESCALER) == TIM2_PRESCALER_256 ) || \ 82 | ((PRESCALER) == TIM2_PRESCALER_512 ) || \ 83 | ((PRESCALER) == TIM2_PRESCALER_1024 ) || \ 84 | ((PRESCALER) == TIM2_PRESCALER_2048 ) || \ 85 | ((PRESCALER) == TIM2_PRESCALER_4096 ) || \ 86 | ((PRESCALER) == TIM2_PRESCALER_8192 ) || \ 87 | ((PRESCALER) == TIM2_PRESCALER_16384 ) || \ 88 | ((PRESCALER) == TIM2_PRESCALER_32768 )) 89 | 90 | /** TIM2 Output Compare and PWM modes */ 91 | typedef enum 92 | { 93 | TIM2_OCMODE_TIMING = ((uint8_t)0x00), 94 | TIM2_OCMODE_ACTIVE = ((uint8_t)0x10), 95 | TIM2_OCMODE_INACTIVE = ((uint8_t)0x20), 96 | TIM2_OCMODE_TOGGLE = ((uint8_t)0x30), 97 | TIM2_OCMODE_PWM1 = ((uint8_t)0x60), 98 | TIM2_OCMODE_PWM2 = ((uint8_t)0x70) 99 | }TIM2_OCMode_TypeDef; 100 | 101 | #define IS_TIM2_OC_MODE_OK(MODE) (((MODE) == TIM2_OCMODE_TIMING) || \ 102 | ((MODE) == TIM2_OCMODE_ACTIVE) || \ 103 | ((MODE) == TIM2_OCMODE_INACTIVE) || \ 104 | ((MODE) == TIM2_OCMODE_TOGGLE)|| \ 105 | ((MODE) == TIM2_OCMODE_PWM1) || \ 106 | ((MODE) == TIM2_OCMODE_PWM2)) 107 | 108 | #define IS_TIM2_OCM_OK(MODE)(((MODE) == TIM2_OCMODE_TIMING) || \ 109 | ((MODE) == TIM2_OCMODE_ACTIVE) || \ 110 | ((MODE) == TIM2_OCMODE_INACTIVE) || \ 111 | ((MODE) == TIM2_OCMODE_TOGGLE)|| \ 112 | ((MODE) == TIM2_OCMODE_PWM1) || \ 113 | ((MODE) == TIM2_OCMODE_PWM2) || \ 114 | ((MODE) == (uint8_t)TIM2_FORCEDACTION_ACTIVE) || \ 115 | ((MODE) == (uint8_t)TIM2_FORCEDACTION_INACTIVE)) 116 | 117 | /** TIM2 One Pulse Mode */ 118 | typedef enum 119 | { 120 | TIM2_OPMODE_SINGLE = ((uint8_t)0x01), 121 | TIM2_OPMODE_REPETITIVE = ((uint8_t)0x00) 122 | }TIM2_OPMode_TypeDef; 123 | 124 | #define IS_TIM2_OPM_MODE_OK(MODE) (((MODE) == TIM2_OPMODE_SINGLE) || \ 125 | ((MODE) == TIM2_OPMODE_REPETITIVE)) 126 | 127 | /** TIM2 Channel */ 128 | typedef enum 129 | { 130 | TIM2_CHANNEL_1 = ((uint8_t)0x00), 131 | TIM2_CHANNEL_2 = ((uint8_t)0x01), 132 | TIM2_CHANNEL_3 = ((uint8_t)0x02) 133 | }TIM2_Channel_TypeDef; 134 | 135 | #define IS_TIM2_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \ 136 | ((CHANNEL) == TIM2_CHANNEL_2) || \ 137 | ((CHANNEL) == TIM2_CHANNEL_3)) 138 | 139 | #define IS_TIM2_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \ 140 | ((CHANNEL) == TIM2_CHANNEL_2)) 141 | 142 | /** TIM2 Output Compare Polarity */ 143 | typedef enum 144 | { 145 | TIM2_OCPOLARITY_HIGH = ((uint8_t)0x00), 146 | TIM2_OCPOLARITY_LOW = ((uint8_t)0x22) 147 | }TIM2_OCPolarity_TypeDef; 148 | 149 | #define IS_TIM2_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_OCPOLARITY_HIGH) || \ 150 | ((POLARITY) == TIM2_OCPOLARITY_LOW)) 151 | 152 | /** TIM2 Output Compare states */ 153 | typedef enum 154 | { 155 | TIM2_OUTPUTSTATE_DISABLE = ((uint8_t)0x00), 156 | TIM2_OUTPUTSTATE_ENABLE = ((uint8_t)0x11) 157 | }TIM2_OutputState_TypeDef; 158 | 159 | #define IS_TIM2_OUTPUT_STATE_OK(STATE) (((STATE) == TIM2_OUTPUTSTATE_DISABLE) || \ 160 | ((STATE) == TIM2_OUTPUTSTATE_ENABLE)) 161 | 162 | /** TIM2 Input Capture Polarity */ 163 | typedef enum 164 | { 165 | TIM2_ICPOLARITY_RISING = ((uint8_t)0x00), 166 | TIM2_ICPOLARITY_FALLING = ((uint8_t)0x44) 167 | }TIM2_ICPolarity_TypeDef; 168 | 169 | #define IS_TIM2_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_ICPOLARITY_RISING) || \ 170 | ((POLARITY) == TIM2_ICPOLARITY_FALLING)) 171 | 172 | /** TIM2 Input Capture Selection */ 173 | typedef enum 174 | { 175 | TIM2_ICSELECTION_DIRECTTI = ((uint8_t)0x01), 176 | TIM2_ICSELECTION_INDIRECTTI = ((uint8_t)0x02), 177 | TIM2_ICSELECTION_TRGI = ((uint8_t)0x03) 178 | }TIM2_ICSelection_TypeDef; 179 | 180 | #define IS_TIM2_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \ 181 | ((SELECTION) == TIM2_ICSELECTION_INDIRECTTI) || \ 182 | ((SELECTION) == TIM2_ICSELECTION_TRGI)) 183 | 184 | #define IS_TIM2_IC_SELECTION1_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \ 185 | ((SELECTION) == TIM2_ICSELECTION_TRGI)) 186 | 187 | /** TIM2 Input Capture Prescaler */ 188 | typedef enum 189 | { 190 | TIM2_ICPSC_DIV1 = ((uint8_t)0x00), 191 | TIM2_ICPSC_DIV2 = ((uint8_t)0x04), 192 | TIM2_ICPSC_DIV4 = ((uint8_t)0x08), 193 | TIM2_ICPSC_DIV8 = ((uint8_t)0x0C) 194 | }TIM2_ICPSC_TypeDef; 195 | 196 | #define IS_TIM2_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_ICPSC_DIV1) || \ 197 | ((PRESCALER) == TIM2_ICPSC_DIV2) || \ 198 | ((PRESCALER) == TIM2_ICPSC_DIV4) || \ 199 | ((PRESCALER) == TIM2_ICPSC_DIV8)) 200 | 201 | /** TIM2 Input Capture Filer Value */ 202 | #define IS_TIM2_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F) 203 | 204 | /** TIM2 interrupt sources */ 205 | typedef enum 206 | { 207 | TIM2_IT_UPDATE = ((uint8_t)0x01), 208 | TIM2_IT_CC1 = ((uint8_t)0x02), 209 | TIM2_IT_CC2 = ((uint8_t)0x04), 210 | TIM2_IT_CC3 = ((uint8_t)0x08) 211 | }TIM2_IT_TypeDef; 212 | 213 | #define IS_TIM2_IT_OK(IT) (((IT) != 0x00) && ((IT) <= 0x0F)) 214 | 215 | #define IS_TIM2_GET_IT_OK(IT) (((IT) == TIM2_IT_UPDATE) || \ 216 | ((IT) == TIM2_IT_CC1) || \ 217 | ((IT) == TIM2_IT_CC2) || \ 218 | ((IT) == TIM2_IT_CC3)) 219 | 220 | /** TIM2 Prescaler Reload Mode */ 221 | typedef enum 222 | { 223 | TIM2_PSCRELOADMODE_UPDATE = ((uint8_t)0x00), 224 | TIM2_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01) 225 | }TIM2_PSCReloadMode_TypeDef; 226 | 227 | #define IS_TIM2_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM2_PSCRELOADMODE_UPDATE) || \ 228 | ((RELOAD) == TIM2_PSCRELOADMODE_IMMEDIATE)) 229 | 230 | /** TIM2 Event Source */ 231 | typedef enum 232 | { 233 | TIM2_EVENTSOURCE_UPDATE = ((uint8_t)0x01), 234 | TIM2_EVENTSOURCE_CC1 = ((uint8_t)0x02), 235 | TIM2_EVENTSOURCE_CC2 = ((uint8_t)0x04), 236 | TIM2_EVENTSOURCE_CC3 = ((uint8_t)0x08) 237 | }TIM2_EventSource_TypeDef; 238 | 239 | #define IS_TIM2_EVENT_SOURCE_OK(SOURCE) (((SOURCE) != 0x00)) 240 | 241 | /** TIM2 Update Source */ 242 | typedef enum 243 | { 244 | TIM2_UPDATESOURCE_GLOBAL = ((uint8_t)0x00), 245 | TIM2_UPDATESOURCE_REGULAR = ((uint8_t)0x01) 246 | }TIM2_UpdateSource_TypeDef; 247 | 248 | #define IS_TIM2_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM2_UPDATESOURCE_GLOBAL) || \ 249 | ((SOURCE) == TIM2_UPDATESOURCE_REGULAR)) 250 | 251 | /** TIM2 Flags */ 252 | typedef enum 253 | { 254 | TIM2_FLAG_UPDATE = ((uint16_t)0x0001), 255 | TIM2_FLAG_CC1 = ((uint16_t)0x0002), 256 | TIM2_FLAG_CC2 = ((uint16_t)0x0004), 257 | TIM2_FLAG_CC3 = ((uint16_t)0x0008), 258 | TIM2_FLAG_CC1OF = ((uint16_t)0x0200), 259 | TIM2_FLAG_CC2OF = ((uint16_t)0x0400), 260 | TIM2_FLAG_CC3OF = ((uint16_t)0x0800) 261 | }TIM2_FLAG_TypeDef; 262 | 263 | #define IS_TIM2_GET_FLAG_OK(FLAG) (((FLAG) == TIM2_FLAG_UPDATE) || \ 264 | ((FLAG) == TIM2_FLAG_CC1) || \ 265 | ((FLAG) == TIM2_FLAG_CC2) || \ 266 | ((FLAG) == TIM2_FLAG_CC3) || \ 267 | ((FLAG) == TIM2_FLAG_CC1OF) || \ 268 | ((FLAG) == TIM2_FLAG_CC2OF) || \ 269 | ((FLAG) == TIM2_FLAG_CC3OF)) 270 | 271 | #define IS_TIM2_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & 0xF1F0) == 0x0000) && ((uint16_t)(FLAG) != 0x0000)) 272 | 273 | /** 274 | * @} 275 | */ 276 | 277 | /* Exported macro ------------------------------------------------------------*/ 278 | 279 | /* Exported functions --------------------------------------------------------*/ 280 | 281 | /** @addtogroup TIM2_Exported_Functions 282 | * @{ 283 | */ 284 | 285 | void TIM2_DeInit(void); 286 | void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler, uint16_t TIM2_Period); 287 | void TIM2_OC1Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 288 | void TIM2_OC2Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 289 | void TIM2_OC3Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 290 | void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter); 291 | void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter); 292 | void TIM2_Cmd(FunctionalState NewState); 293 | void TIM2_ITConfig(TIM2_IT_TypeDef TIM2_IT, FunctionalState NewState); 294 | void TIM2_InternalClockConfig(void); 295 | void TIM2_UpdateDisableConfig(FunctionalState NewState); 296 | void TIM2_UpdateRequestConfig(TIM2_UpdateSource_TypeDef TIM2_UpdateSource); 297 | void TIM2_SelectOnePulseMode(TIM2_OPMode_TypeDef TIM2_OPMode); 298 | void TIM2_PrescalerConfig(TIM2_Prescaler_TypeDef Prescaler, TIM2_PSCReloadMode_TypeDef TIM2_PSCReloadMode); 299 | void TIM2_ForcedOC1Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 300 | void TIM2_ForcedOC2Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 301 | void TIM2_ForcedOC3Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction); 302 | void TIM2_ARRPreloadConfig(FunctionalState NewState); 303 | void TIM2_CCPreloadControl(FunctionalState NewState); 304 | void TIM2_OC1PreloadConfig(FunctionalState NewState); 305 | void TIM2_OC2PreloadConfig(FunctionalState NewState); 306 | void TIM2_OC3PreloadConfig(FunctionalState NewState); 307 | void TIM2_GenerateEvent(TIM2_EventSource_TypeDef TIM2_EventSource); 308 | void TIM2_OC1PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 309 | void TIM2_OC2PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 310 | void TIM2_OC3PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity); 311 | void TIM2_CCxCmd(TIM2_Channel_TypeDef TIM2_Channel, FunctionalState NewState); 312 | void TIM2_SelectOCxM(TIM2_Channel_TypeDef TIM2_Channel, TIM2_OCMode_TypeDef TIM2_OCMode); 313 | void TIM2_SetCounter(uint16_t Counter); 314 | void TIM2_SetAutoreload(uint16_t Autoreload); 315 | void TIM2_SetCompare1(uint16_t Compare1); 316 | void TIM2_SetCompare2(uint16_t Compare2); 317 | void TIM2_SetCompare3(uint16_t Compare3); 318 | void TIM2_SetIC1Prescaler(TIM2_ICPSC_TypeDef TIM2_IC1Prescaler); 319 | void TIM2_SetIC2Prescaler(TIM2_ICPSC_TypeDef TIM2_IC2Prescaler); 320 | void TIM2_SetIC3Prescaler(TIM2_ICPSC_TypeDef TIM2_IC3Prescaler); 321 | uint16_t TIM2_GetCapture1(void); 322 | uint16_t TIM2_GetCapture2(void); 323 | uint16_t TIM2_GetCapture3(void); 324 | uint16_t TIM2_GetCounter(void); 325 | TIM2_Prescaler_TypeDef TIM2_GetPrescaler(void); 326 | FlagStatus TIM2_GetFlagStatus(TIM2_FLAG_TypeDef TIM2_FLAG); 327 | void TIM2_ClearFlag(TIM2_FLAG_TypeDef TIM2_FLAG); 328 | ITStatus TIM2_GetITStatus(TIM2_IT_TypeDef TIM2_IT); 329 | void TIM2_ClearITPendingBit(TIM2_IT_TypeDef TIM2_IT); 330 | 331 | /** 332 | * @} 333 | */ 334 | 335 | #endif /* __STM8S_TIM2_H */ 336 | 337 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 338 | -------------------------------------------------------------------------------- /include/stm8s_tim3.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim3.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM3 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM3_H 30 | #define __STM8S_TIM3_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup TIM3_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** TIM3 Forced Action */ 46 | typedef enum 47 | { 48 | TIM3_FORCEDACTION_ACTIVE = ((uint8_t)0x50), 49 | TIM3_FORCEDACTION_INACTIVE = ((uint8_t)0x40) 50 | } TIM3_ForcedAction_TypeDef; 51 | 52 | #define IS_TIM3_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM3_FORCEDACTION_ACTIVE) || \ 53 | ((ACTION) == TIM3_FORCEDACTION_INACTIVE)) 54 | 55 | /** TIM3 Prescaler */ 56 | typedef enum 57 | { 58 | TIM3_PRESCALER_1 = ((uint8_t)0x00), 59 | TIM3_PRESCALER_2 = ((uint8_t)0x01), 60 | TIM3_PRESCALER_4 = ((uint8_t)0x02), 61 | TIM3_PRESCALER_8 = ((uint8_t)0x03), 62 | TIM3_PRESCALER_16 = ((uint8_t)0x04), 63 | TIM3_PRESCALER_32 = ((uint8_t)0x05), 64 | TIM3_PRESCALER_64 = ((uint8_t)0x06), 65 | TIM3_PRESCALER_128 = ((uint8_t)0x07), 66 | TIM3_PRESCALER_256 = ((uint8_t)0x08), 67 | TIM3_PRESCALER_512 = ((uint8_t)0x09), 68 | TIM3_PRESCALER_1024 = ((uint8_t)0x0A), 69 | TIM3_PRESCALER_2048 = ((uint8_t)0x0B), 70 | TIM3_PRESCALER_4096 = ((uint8_t)0x0C), 71 | TIM3_PRESCALER_8192 = ((uint8_t)0x0D), 72 | TIM3_PRESCALER_16384 = ((uint8_t)0x0E), 73 | TIM3_PRESCALER_32768 = ((uint8_t)0x0F) 74 | } TIM3_Prescaler_TypeDef; 75 | 76 | #define IS_TIM3_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM3_PRESCALER_1 ) || \ 77 | ((PRESCALER) == TIM3_PRESCALER_2 ) || \ 78 | ((PRESCALER) == TIM3_PRESCALER_4 ) || \ 79 | ((PRESCALER) == TIM3_PRESCALER_8 ) || \ 80 | ((PRESCALER) == TIM3_PRESCALER_16 ) || \ 81 | ((PRESCALER) == TIM3_PRESCALER_32 ) || \ 82 | ((PRESCALER) == TIM3_PRESCALER_64 ) || \ 83 | ((PRESCALER) == TIM3_PRESCALER_128 ) || \ 84 | ((PRESCALER) == TIM3_PRESCALER_256 ) || \ 85 | ((PRESCALER) == TIM3_PRESCALER_512 ) || \ 86 | ((PRESCALER) == TIM3_PRESCALER_1024 ) || \ 87 | ((PRESCALER) == TIM3_PRESCALER_2048 ) || \ 88 | ((PRESCALER) == TIM3_PRESCALER_4096 ) || \ 89 | ((PRESCALER) == TIM3_PRESCALER_8192 ) || \ 90 | ((PRESCALER) == TIM3_PRESCALER_16384 ) || \ 91 | ((PRESCALER) == TIM3_PRESCALER_32768 )) 92 | 93 | /** TIM3 Output Compare and PWM modes */ 94 | typedef enum 95 | { 96 | TIM3_OCMODE_TIMING = ((uint8_t)0x00), 97 | TIM3_OCMODE_ACTIVE = ((uint8_t)0x10), 98 | TIM3_OCMODE_INACTIVE = ((uint8_t)0x20), 99 | TIM3_OCMODE_TOGGLE = ((uint8_t)0x30), 100 | TIM3_OCMODE_PWM1 = ((uint8_t)0x60), 101 | TIM3_OCMODE_PWM2 = ((uint8_t)0x70) 102 | } TIM3_OCMode_TypeDef; 103 | 104 | #define IS_TIM3_OC_MODE_OK(MODE) (((MODE) == TIM3_OCMODE_TIMING) || \ 105 | ((MODE) == TIM3_OCMODE_ACTIVE) || \ 106 | ((MODE) == TIM3_OCMODE_INACTIVE) || \ 107 | ((MODE) == TIM3_OCMODE_TOGGLE)|| \ 108 | ((MODE) == TIM3_OCMODE_PWM1) || \ 109 | ((MODE) == TIM3_OCMODE_PWM2)) 110 | 111 | #define IS_TIM3_OCM_OK(MODE)(((MODE) == TIM3_OCMODE_TIMING) || \ 112 | ((MODE) == TIM3_OCMODE_ACTIVE) || \ 113 | ((MODE) == TIM3_OCMODE_INACTIVE) || \ 114 | ((MODE) == TIM3_OCMODE_TOGGLE)|| \ 115 | ((MODE) == TIM3_OCMODE_PWM1) || \ 116 | ((MODE) == TIM3_OCMODE_PWM2) || \ 117 | ((MODE) == (uint8_t)TIM3_FORCEDACTION_ACTIVE) || \ 118 | ((MODE) == (uint8_t)TIM3_FORCEDACTION_INACTIVE)) 119 | 120 | /** TIM3 One Pulse Mode */ 121 | typedef enum 122 | { 123 | TIM3_OPMODE_SINGLE = ((uint8_t)0x01), 124 | TIM3_OPMODE_REPETITIVE = ((uint8_t)0x00) 125 | } TIM3_OPMode_TypeDef; 126 | 127 | #define IS_TIM3_OPM_MODE_OK(MODE) (((MODE) == TIM3_OPMODE_SINGLE) || \ 128 | ((MODE) == TIM3_OPMODE_REPETITIVE)) 129 | 130 | /** TIM3 Channel */ 131 | 132 | typedef enum 133 | { 134 | TIM3_CHANNEL_1 = ((uint8_t)0x00), 135 | TIM3_CHANNEL_2 = ((uint8_t)0x01) 136 | } TIM3_Channel_TypeDef; 137 | 138 | #define IS_TIM3_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM3_CHANNEL_1) || \ 139 | ((CHANNEL) == TIM3_CHANNEL_2)) 140 | 141 | #define IS_TIM3_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM3_CHANNEL_1) || \ 142 | ((CHANNEL) == TIM3_CHANNEL_2)) 143 | 144 | /** TIM3 Output Compare Polarity */ 145 | typedef enum 146 | { 147 | TIM3_OCPOLARITY_HIGH = ((uint8_t)0x00), 148 | TIM3_OCPOLARITY_LOW = ((uint8_t)0x22) 149 | } TIM3_OCPolarity_TypeDef; 150 | 151 | #define IS_TIM3_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM3_OCPOLARITY_HIGH) || \ 152 | ((POLARITY) == TIM3_OCPOLARITY_LOW)) 153 | 154 | /** TIM3 Output Compare states */ 155 | typedef enum 156 | { 157 | TIM3_OUTPUTSTATE_DISABLE = ((uint8_t)0x00), 158 | TIM3_OUTPUTSTATE_ENABLE = ((uint8_t)0x11) 159 | } TIM3_OutputState_TypeDef; 160 | 161 | #define IS_TIM3_OUTPUT_STATE_OK(STATE) (((STATE) == TIM3_OUTPUTSTATE_DISABLE) || \ 162 | ((STATE) == TIM3_OUTPUTSTATE_ENABLE)) 163 | 164 | /** TIM3 Input Capture Polarity */ 165 | typedef enum 166 | { 167 | TIM3_ICPOLARITY_RISING = ((uint8_t)0x00), 168 | TIM3_ICPOLARITY_FALLING = ((uint8_t)0x44) 169 | } TIM3_ICPolarity_TypeDef; 170 | 171 | #define IS_TIM3_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM3_ICPOLARITY_RISING) || \ 172 | ((POLARITY) == TIM3_ICPOLARITY_FALLING)) 173 | 174 | /** TIM3 Input Capture Selection */ 175 | typedef enum 176 | { 177 | TIM3_ICSELECTION_DIRECTTI = ((uint8_t)0x01), 178 | TIM3_ICSELECTION_INDIRECTTI = ((uint8_t)0x02), 179 | TIM3_ICSELECTION_TRGI = ((uint8_t)0x03) 180 | } TIM3_ICSelection_TypeDef; 181 | 182 | #define IS_TIM3_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM3_ICSELECTION_DIRECTTI) || \ 183 | ((SELECTION) == TIM3_ICSELECTION_INDIRECTTI) || \ 184 | ((SELECTION) == TIM3_ICSELECTION_TRGI)) 185 | 186 | /** TIM3 Input Capture Prescaler */ 187 | typedef enum 188 | { 189 | TIM3_ICPSC_DIV1 = ((uint8_t)0x00), 190 | TIM3_ICPSC_DIV2 = ((uint8_t)0x04), 191 | TIM3_ICPSC_DIV4 = ((uint8_t)0x08), 192 | TIM3_ICPSC_DIV8 = ((uint8_t)0x0C) 193 | } TIM3_ICPSC_TypeDef; 194 | 195 | #define IS_TIM3_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM3_ICPSC_DIV1) || \ 196 | ((PRESCALER) == TIM3_ICPSC_DIV2) || \ 197 | ((PRESCALER) == TIM3_ICPSC_DIV4) || \ 198 | ((PRESCALER) == TIM3_ICPSC_DIV8)) 199 | 200 | /** TIM3 Input Capture Filer Value */ 201 | #define IS_TIM3_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F) 202 | 203 | /** TIM3 interrupt sources */ 204 | typedef enum 205 | { 206 | TIM3_IT_UPDATE = ((uint8_t)0x01), 207 | TIM3_IT_CC1 = ((uint8_t)0x02), 208 | TIM3_IT_CC2 = ((uint8_t)0x04) 209 | } TIM3_IT_TypeDef; 210 | 211 | #define IS_TIM3_IT_OK(IT) (((IT) != 0x00) && ((IT) <= 0x07)) 212 | 213 | #define IS_TIM3_GET_IT_OK(IT) (((IT) == TIM3_IT_UPDATE) || \ 214 | ((IT) == TIM3_IT_CC1) || \ 215 | ((IT) == TIM3_IT_CC2)) 216 | 217 | /** TIM3 Prescaler Reload Mode */ 218 | typedef enum 219 | { 220 | TIM3_PSCRELOADMODE_UPDATE = ((uint8_t)0x00), 221 | TIM3_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01) 222 | } TIM3_PSCReloadMode_TypeDef; 223 | 224 | #define IS_TIM3_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM3_PSCRELOADMODE_UPDATE) || \ 225 | ((RELOAD) == TIM3_PSCRELOADMODE_IMMEDIATE)) 226 | 227 | /** TIM3 Event Source */ 228 | typedef enum 229 | { 230 | TIM3_EVENTSOURCE_UPDATE = ((uint8_t)0x01), 231 | TIM3_EVENTSOURCE_CC1 = ((uint8_t)0x02), 232 | TIM3_EVENTSOURCE_CC2 = ((uint8_t)0x04) 233 | } TIM3_EventSource_TypeDef; 234 | 235 | #define IS_TIM3_EVENT_SOURCE_OK(SOURCE) (((SOURCE) != 0x00)) 236 | 237 | /** TIM3 Update Source */ 238 | typedef enum 239 | { 240 | TIM3_UPDATESOURCE_GLOBAL = ((uint8_t)0x00), 241 | TIM3_UPDATESOURCE_REGULAR = ((uint8_t)0x01) 242 | } TIM3_UpdateSource_TypeDef; 243 | 244 | #define IS_TIM3_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM3_UPDATESOURCE_GLOBAL) || \ 245 | ((SOURCE) == TIM3_UPDATESOURCE_REGULAR)) 246 | 247 | /** TIM3 Flags */ 248 | typedef enum 249 | { 250 | TIM3_FLAG_UPDATE = ((uint16_t)0x0001), 251 | TIM3_FLAG_CC1 = ((uint16_t)0x0002), 252 | TIM3_FLAG_CC2 = ((uint16_t)0x0004), 253 | TIM3_FLAG_CC1OF = ((uint16_t)0x0200), 254 | TIM3_FLAG_CC2OF = ((uint16_t)0x0400) 255 | } TIM3_FLAG_TypeDef; 256 | 257 | #define IS_TIM3_GET_FLAG_OK(FLAG) (((FLAG) == TIM3_FLAG_UPDATE) || \ 258 | ((FLAG) == TIM3_FLAG_CC1) || \ 259 | ((FLAG) == TIM3_FLAG_CC2) || \ 260 | ((FLAG) == TIM3_FLAG_CC1OF) || \ 261 | ((FLAG) == TIM3_FLAG_CC2OF) ) 262 | 263 | #define IS_TIM3_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & 0xF9F8) == 0x0000) && ((uint16_t)(FLAG)!= 0x0000)) 264 | 265 | /** 266 | * @} 267 | */ 268 | 269 | /* Exported macro ------------------------------------------------------------*/ 270 | 271 | /* Exported functions --------------------------------------------------------*/ 272 | 273 | /** @addtogroup TIM3_Exported_Functions 274 | * @{ 275 | */ 276 | 277 | void TIM3_DeInit(void); 278 | void TIM3_TimeBaseInit(TIM3_Prescaler_TypeDef TIM3_Prescaler, uint16_t TIM3_Period); 279 | void TIM3_OC1Init(TIM3_OCMode_TypeDef TIM3_OCMode, TIM3_OutputState_TypeDef TIM3_OutputState, uint16_t TIM3_Pulse, TIM3_OCPolarity_TypeDef TIM3_OCPolarity); 280 | void TIM3_OC2Init(TIM3_OCMode_TypeDef TIM3_OCMode, TIM3_OutputState_TypeDef TIM3_OutputState, uint16_t TIM3_Pulse, TIM3_OCPolarity_TypeDef TIM3_OCPolarity); 281 | void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter); 282 | void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter); 283 | void TIM3_Cmd(FunctionalState NewState); 284 | void TIM3_ITConfig(TIM3_IT_TypeDef TIM3_IT, FunctionalState NewState); 285 | void TIM3_InternalClockConfig(void); 286 | void TIM3_UpdateDisableConfig(FunctionalState NewState); 287 | void TIM3_UpdateRequestConfig(TIM3_UpdateSource_TypeDef TIM3_UpdateSource); 288 | void TIM3_SelectOnePulseMode(TIM3_OPMode_TypeDef TIM3_OPMode); 289 | void TIM3_PrescalerConfig(TIM3_Prescaler_TypeDef Prescaler, TIM3_PSCReloadMode_TypeDef TIM3_PSCReloadMode); 290 | void TIM3_ForcedOC1Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction); 291 | void TIM3_ForcedOC2Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction); 292 | void TIM3_ARRPreloadConfig(FunctionalState NewState); 293 | void TIM3_CCPreloadControl(FunctionalState NewState); 294 | void TIM3_OC1PreloadConfig(FunctionalState NewState); 295 | void TIM3_OC2PreloadConfig(FunctionalState NewState); 296 | void TIM3_GenerateEvent(TIM3_EventSource_TypeDef TIM3_EventSource); 297 | void TIM3_OC1PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity); 298 | void TIM3_OC2PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity); 299 | void TIM3_CCxCmd(TIM3_Channel_TypeDef TIM3_Channel, FunctionalState NewState); 300 | void TIM3_SelectOCxM(TIM3_Channel_TypeDef TIM3_Channel, TIM3_OCMode_TypeDef TIM3_OCMode); 301 | void TIM3_SetCounter(uint16_t Counter); 302 | void TIM3_SetAutoreload(uint16_t Autoreload); 303 | void TIM3_SetCompare1(uint16_t Compare1); 304 | void TIM3_SetCompare2(uint16_t Compare2); 305 | void TIM3_SetIC1Prescaler(TIM3_ICPSC_TypeDef TIM3_IC1Prescaler); 306 | void TIM3_SetIC2Prescaler(TIM3_ICPSC_TypeDef TIM3_IC2Prescaler); 307 | uint16_t TIM3_GetCapture1(void); 308 | uint16_t TIM3_GetCapture2(void); 309 | uint16_t TIM3_GetCounter(void); 310 | TIM3_Prescaler_TypeDef TIM3_GetPrescaler(void); 311 | FlagStatus TIM3_GetFlagStatus(TIM3_FLAG_TypeDef TIM3_FLAG); 312 | void TIM3_ClearFlag(TIM3_FLAG_TypeDef TIM3_FLAG); 313 | ITStatus TIM3_GetITStatus(TIM3_IT_TypeDef TIM3_IT); 314 | void TIM3_ClearITPendingBit(TIM3_IT_TypeDef TIM3_IT); 315 | 316 | /** 317 | * @} 318 | */ 319 | 320 | #endif /* __STM8S_TIM3_H */ 321 | 322 | /** 323 | * @} 324 | */ 325 | 326 | 327 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 328 | -------------------------------------------------------------------------------- /include/stm8s_tim4.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim4.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM4 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM4_H 30 | #define __STM8S_TIM4_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup TIM4_Exported_Types 42 | * @{ 43 | */ 44 | 45 | 46 | 47 | /** TIM4 Prescaler */ 48 | typedef enum 49 | { 50 | TIM4_PRESCALER_1 = ((uint8_t)0x00), 51 | TIM4_PRESCALER_2 = ((uint8_t)0x01), 52 | TIM4_PRESCALER_4 = ((uint8_t)0x02), 53 | TIM4_PRESCALER_8 = ((uint8_t)0x03), 54 | TIM4_PRESCALER_16 = ((uint8_t)0x04), 55 | TIM4_PRESCALER_32 = ((uint8_t)0x05), 56 | TIM4_PRESCALER_64 = ((uint8_t)0x06), 57 | TIM4_PRESCALER_128 = ((uint8_t)0x07) 58 | } TIM4_Prescaler_TypeDef; 59 | 60 | #define IS_TIM4_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM4_PRESCALER_1 ) || \ 61 | ((PRESCALER) == TIM4_PRESCALER_2 ) || \ 62 | ((PRESCALER) == TIM4_PRESCALER_4 ) || \ 63 | ((PRESCALER) == TIM4_PRESCALER_8 ) || \ 64 | ((PRESCALER) == TIM4_PRESCALER_16 ) || \ 65 | ((PRESCALER) == TIM4_PRESCALER_32 ) || \ 66 | ((PRESCALER) == TIM4_PRESCALER_64 ) || \ 67 | ((PRESCALER) == TIM4_PRESCALER_128 ) ) 68 | 69 | /** TIM4 One Pulse Mode */ 70 | typedef enum 71 | { 72 | TIM4_OPMODE_SINGLE = ((uint8_t)0x01), 73 | TIM4_OPMODE_REPETITIVE = ((uint8_t)0x00) 74 | } TIM4_OPMode_TypeDef; 75 | 76 | #define IS_TIM4_OPM_MODE_OK(MODE) (((MODE) == TIM4_OPMODE_SINGLE) || \ 77 | ((MODE) == TIM4_OPMODE_REPETITIVE)) 78 | 79 | /** TIM4 Prescaler Reload Mode */ 80 | typedef enum 81 | { 82 | TIM4_PSCRELOADMODE_UPDATE = ((uint8_t)0x00), 83 | TIM4_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01) 84 | } TIM4_PSCReloadMode_TypeDef; 85 | 86 | #define IS_TIM4_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM4_PSCRELOADMODE_UPDATE) || \ 87 | ((RELOAD) == TIM4_PSCRELOADMODE_IMMEDIATE)) 88 | 89 | /** TIM4 Update Source */ 90 | typedef enum 91 | { 92 | TIM4_UPDATESOURCE_GLOBAL = ((uint8_t)0x00), 93 | TIM4_UPDATESOURCE_REGULAR = ((uint8_t)0x01) 94 | } TIM4_UpdateSource_TypeDef; 95 | 96 | #define IS_TIM4_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM4_UPDATESOURCE_GLOBAL) || \ 97 | ((SOURCE) == TIM4_UPDATESOURCE_REGULAR)) 98 | 99 | /** TIM4 Event Source */ 100 | typedef enum 101 | { 102 | TIM4_EVENTSOURCE_UPDATE = ((uint8_t)0x01) 103 | }TIM4_EventSource_TypeDef; 104 | 105 | #define IS_TIM4_EVENT_SOURCE_OK(SOURCE) (((SOURCE) == 0x01)) 106 | 107 | /** TIM4 Flags */ 108 | typedef enum 109 | { 110 | TIM4_FLAG_UPDATE = ((uint8_t)0x01) 111 | }TIM4_FLAG_TypeDef; 112 | 113 | #define IS_TIM4_GET_FLAG_OK(FLAG) ((FLAG) == TIM4_FLAG_UPDATE) 114 | 115 | 116 | 117 | /** TIM4 interrupt sources */ 118 | typedef enum 119 | { 120 | TIM4_IT_UPDATE = ((uint8_t)0x01) 121 | }TIM4_IT_TypeDef; 122 | 123 | #define IS_TIM4_IT_OK(IT) ((IT) == TIM4_IT_UPDATE) 124 | 125 | 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /* Exported macro ------------------------------------------------------------*/ 132 | 133 | /* Exported functions --------------------------------------------------------*/ 134 | 135 | /** @addtogroup TIM4_Exported_Functions 136 | * @{ 137 | */ 138 | void TIM4_DeInit(void); 139 | void TIM4_TimeBaseInit(TIM4_Prescaler_TypeDef TIM4_Prescaler, uint8_t TIM4_Period); 140 | void TIM4_Cmd(FunctionalState NewState); 141 | void TIM4_ITConfig(TIM4_IT_TypeDef TIM4_IT, FunctionalState NewState); 142 | void TIM4_UpdateDisableConfig(FunctionalState NewState); 143 | void TIM4_UpdateRequestConfig(TIM4_UpdateSource_TypeDef TIM4_UpdateSource); 144 | void TIM4_SelectOnePulseMode(TIM4_OPMode_TypeDef TIM4_OPMode); 145 | void TIM4_PrescalerConfig(TIM4_Prescaler_TypeDef Prescaler, TIM4_PSCReloadMode_TypeDef TIM4_PSCReloadMode); 146 | void TIM4_ARRPreloadConfig(FunctionalState NewState); 147 | void TIM4_GenerateEvent(TIM4_EventSource_TypeDef TIM4_EventSource); 148 | void TIM4_SetCounter(uint8_t Counter); 149 | void TIM4_SetAutoreload(uint8_t Autoreload); 150 | uint8_t TIM4_GetCounter(void); 151 | TIM4_Prescaler_TypeDef TIM4_GetPrescaler(void); 152 | FlagStatus TIM4_GetFlagStatus(TIM4_FLAG_TypeDef TIM4_FLAG); 153 | void TIM4_ClearFlag(TIM4_FLAG_TypeDef TIM4_FLAG); 154 | ITStatus TIM4_GetITStatus(TIM4_IT_TypeDef TIM4_IT); 155 | void TIM4_ClearITPendingBit(TIM4_IT_TypeDef TIM4_IT); 156 | 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | #endif /* __STM8S_TIM4_H */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | 169 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 170 | -------------------------------------------------------------------------------- /include/stm8s_tim6.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_tim6.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the TIM6 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_TIM6_H 30 | #define __STM8S_TIM6_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported variables ------------------------------------------------------- */ 40 | /* Exported types ------------------------------------------------------------*/ 41 | 42 | /** @addtogroup TIM6_Exported_Types 43 | * @{ 44 | */ 45 | 46 | 47 | /** 48 | * @brief TIM6 Prescaler 49 | */ 50 | typedef enum 51 | { 52 | TIM6_PRESCALER_1 = ((uint8_t)0x00), /*!< Time base Prescaler = 1 (No effect)*/ 53 | TIM6_PRESCALER_2 = ((uint8_t)0x01), /*!< Time base Prescaler = 2 */ 54 | TIM6_PRESCALER_4 = ((uint8_t)0x02), /*!< Time base Prescaler = 4 */ 55 | TIM6_PRESCALER_8 = ((uint8_t)0x03), /*!< Time base Prescaler = 8 */ 56 | TIM6_PRESCALER_16 = ((uint8_t)0x04), /*!< Time base Prescaler = 16 */ 57 | TIM6_PRESCALER_32 = ((uint8_t)0x05), /*!< Time base Prescaler = 32 */ 58 | TIM6_PRESCALER_64 = ((uint8_t)0x06), /*!< Time base Prescaler = 64 */ 59 | TIM6_PRESCALER_128 = ((uint8_t)0x07) /*!< Time base Prescaler = 128 */ 60 | }TIM6_Prescaler_TypeDef; 61 | 62 | /** 63 | * @brief TIM6 One Pulse Mode 64 | */ 65 | typedef enum 66 | { 67 | TIM6_OPMODE_SINGLE = ((uint8_t)0x01), /*!< Single one Pulse mode (OPM Active) */ 68 | TIM6_OPMODE_REPETITIVE = ((uint8_t)0x00) /*!< Repetitive Pulse mode (OPM inactive) */ 69 | }TIM6_OPMode_TypeDef; 70 | 71 | /** 72 | * @brief TIM6 Prescaler Reload Mode 73 | */ 74 | typedef enum 75 | { 76 | TIM6_PSCRELOADMODE_UPDATE =((uint8_t)0x00), /*!< Prescaler value is reloaded at every update*/ 77 | TIM6_PSCRELOADMODE_IMMEDIATE =((uint8_t)0x01) /*!< Prescaler value is reloaded immediately*/ 78 | }TIM6_PSCReloadMode_TypeDef; 79 | 80 | /** 81 | * @brief TIM6 Update Source 82 | */ 83 | typedef enum 84 | { 85 | TIM6_UPDATESOURCE_GLOBAL =((uint8_t)0x00), /*!< Global Update request source */ 86 | TIM6_UPDATESOURCE_REGULAR =((uint8_t)0x01) /*!< Regular Update request source */ 87 | }TIM6_UpdateSource_TypeDef; 88 | 89 | /** 90 | * @brief TIM6 Event Source 91 | */ 92 | typedef enum 93 | { 94 | TIM6_EVENTSOURCE_UPDATE = ((uint8_t)0x01), /*!< Update Event*/ 95 | TIM6_EVENTSOURCE_TRIGGER = ((uint8_t)0x40) /*!< Trigger Event*/ 96 | }TIM6_EventSource_TypeDef; 97 | 98 | /** 99 | * @brief TIM6 Trigger Output Source 100 | */ 101 | typedef enum 102 | { 103 | TIM6_TRGOSOURCE_RESET = ((uint8_t)0x00), /*!< Trigger Output source = Reset*/ 104 | TIM6_TRGOSOURCE_ENABLE = ((uint8_t)0x10), /*!< Trigger Output source = TIM5 is enabled*/ 105 | TIM6_TRGOSOURCE_UPDATE = ((uint8_t)0x20) /*!< Trigger Output source = Update event*/ 106 | }TIM6_TRGOSource_TypeDef; 107 | 108 | /** 109 | * @brief TIM6 Slave Mode 110 | */ 111 | typedef enum 112 | { 113 | TIM6_SLAVEMODE_DISABLE = ((uint8_t)0x00), /*!< Disable slave mode to clock the prescaler directly with the internal clock */ 114 | TIM6_SLAVEMODE_RESET = ((uint8_t)0x04), /*!< Slave Mode Selection = Reset*/ 115 | TIM6_SLAVEMODE_GATED = ((uint8_t)0x05), /*!< Slave Mode Selection = Gated*/ 116 | TIM6_SLAVEMODE_TRIGGER = ((uint8_t)0x06), /*!< Slave Mode Selection = Trigger*/ 117 | TIM6_SLAVEMODE_EXTERNAL1 = ((uint8_t)0x07) /*!< Slave Mode Selection = External 1*/ 118 | }TIM6_SlaveMode_TypeDef; 119 | 120 | /** 121 | * @brief TIM6 Flags 122 | */ 123 | typedef enum 124 | { 125 | TIM6_FLAG_UPDATE = ((uint8_t)0x01), /*!< Update Flag */ 126 | TIM6_FLAG_TRIGGER = ((uint8_t)0x40) /*!< Trigger Flag */ 127 | }TIM6_FLAG_TypeDef; 128 | 129 | /** 130 | * @brief TIM6 interrupt sources 131 | */ 132 | typedef enum 133 | { 134 | TIM6_IT_UPDATE = ((uint8_t)0x01), /*!< Update Interrupt*/ 135 | TIM6_IT_TRIGGER = ((uint8_t)0x40) /*!< Trigger Interrupt*/ 136 | }TIM6_IT_TypeDef; 137 | 138 | /** 139 | * @brief TIM6 Internal Trigger Selection 140 | */ 141 | typedef enum 142 | { 143 | TIM6_TS_TIM1 = ((uint8_t)0x20),/*!< TRIG Input source = TIM1 TRIG Output */ 144 | TIM6_TS_TIM5 = ((uint8_t)0x30) /*!< TRIG Input source = TIM5 TRIG Output */ 145 | }TIM6_TS_TypeDef; 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | /* Exported constants --------------------------------------------------------*/ 152 | /* Exported macros -----------------------------------------------------------*/ 153 | /* Private macros ------------------------------------------------------------*/ 154 | 155 | /** @addtogroup TIM6_Private_Macros 156 | * @{ 157 | */ 158 | 159 | /** 160 | * @brief Macro used by the assert function to check the different functions parameters. 161 | */ 162 | 163 | /** 164 | * @brief Macro TIM6 Prescaler 165 | */ 166 | #define IS_TIM6_PRESCALER_OK(PRESCALER) \ 167 | (((PRESCALER) == TIM6_PRESCALER_1) || \ 168 | ((PRESCALER) == TIM6_PRESCALER_2) || \ 169 | ((PRESCALER) == TIM6_PRESCALER_4) || \ 170 | ((PRESCALER) == TIM6_PRESCALER_8) || \ 171 | ((PRESCALER) == TIM6_PRESCALER_16) || \ 172 | ((PRESCALER) == TIM6_PRESCALER_32) || \ 173 | ((PRESCALER) == TIM6_PRESCALER_64) || \ 174 | ((PRESCALER) == TIM6_PRESCALER_128)) 175 | /** 176 | * @brief Macro TIM6 One Pulse Mode 177 | */ 178 | #define IS_TIM6_OPM_MODE_OK(MODE) \ 179 | (((MODE) == TIM6_OPMODE_SINGLE) || \ 180 | ((MODE) == TIM6_OPMODE_REPETITIVE)) 181 | 182 | /** 183 | * @brief Macro TIM6 Prescaler reload 184 | */ 185 | #define IS_TIM6_PRESCALER_RELOAD_OK(RELOAD) \ 186 | (((RELOAD) == TIM6_PSCRELOADMODE_UPDATE) || \ 187 | ((RELOAD) == TIM6_PSCRELOADMODE_IMMEDIATE)) 188 | /** 189 | * @brief Macro TIM6 Update source 190 | */ 191 | #define IS_TIM6_UPDATE_SOURCE_OK(SOURCE) \ 192 | (((SOURCE) == TIM6_UPDATESOURCE_GLOBAL) || \ 193 | ((SOURCE) == TIM6_UPDATESOURCE_REGULAR)) 194 | /** 195 | * @brief Macro TIM6 Event source 196 | */ 197 | #define IS_TIM6_EVENT_SOURCE_OK(SOURCE) \ 198 | ((((SOURCE) & (uint8_t)0xBE) == 0x00) && \ 199 | ((SOURCE) != 0x00)) 200 | 201 | /** 202 | * @brief Macro TIM6 TRGO source 203 | */ 204 | #define IS_TIM6_TRGO_SOURCE_OK(SOURCE) \ 205 | (((SOURCE) == TIM6_TRGOSOURCE_RESET) || \ 206 | ((SOURCE) == TIM6_TRGOSOURCE_ENABLE)|| \ 207 | ((SOURCE) == TIM6_TRGOSOURCE_UPDATE)) 208 | /** 209 | * @brief Macro TIM6 Slave mode 210 | */ 211 | #define IS_TIM6_SLAVE_MODE_OK(MODE) \ 212 | (((MODE) == TIM6_SLAVEMODE_DISABLE) || \ 213 | ((MODE) == TIM6_SLAVEMODE_RESET) || \ 214 | ((MODE) == TIM6_SLAVEMODE_GATED) || \ 215 | ((MODE) == TIM6_SLAVEMODE_TRIGGER) || \ 216 | ((MODE) == TIM6_SLAVEMODE_EXTERNAL1)) 217 | /** 218 | * @brief Macro TIM6 Flags 219 | */ 220 | #define IS_TIM6_GET_FLAG_OK(FLAG) \ 221 | (((FLAG) == TIM6_FLAG_UPDATE) || \ 222 | ((FLAG) == TIM6_FLAG_TRIGGER)) 223 | 224 | #define IS_TIM6_CLEAR_FLAG_OK(FLAG) \ 225 | ((((FLAG) & (uint8_t)0xBE) == 0x00) && ((FLAG) != 0x00)) 226 | /** 227 | * @brief Macro TIM6 interrupts 228 | */ 229 | #define IS_TIM6_IT_OK(IT) \ 230 | (((IT) != 0x00) && \ 231 | (((IT) & (uint8_t)(~(uint8_t)(0x41)))== 0x00)) 232 | 233 | #define IS_TIM6_GET_IT_OK(IT) \ 234 | (((IT) == TIM6_IT_UPDATE) || \ 235 | ((IT) == TIM6_IT_TRIGGER)) 236 | /** 237 | * @brief Macro TIM6 Trigger selection 238 | */ 239 | #define IS_TIM6_TRIGGER_SELECTION_OK(SELECTION) \ 240 | (((SELECTION) == TIM6_TS_TIM5) || \ 241 | ((SELECTION) == TIM6_TS_TIM1)) 242 | /** 243 | * @} 244 | */ 245 | 246 | /* Exported functions --------------------------------------------------------*/ 247 | 248 | /** @addtogroup TIM6_Exported_Functions 249 | * @{ 250 | */ 251 | 252 | void TIM6_DeInit(void); 253 | void TIM6_TimeBaseInit(TIM6_Prescaler_TypeDef TIM6_Prescaler, uint8_t TIM6_Period); 254 | void TIM6_Cmd(FunctionalState NewState); 255 | void TIM6_UpdateDisableConfig(FunctionalState NewState); 256 | void TIM6_UpdateRequestConfig(TIM6_UpdateSource_TypeDef TIM6_UpdateSource); 257 | void TIM6_SelectOnePulseMode(TIM6_OPMode_TypeDef TIM6_OPMode); 258 | void TIM6_PrescalerConfig(TIM6_Prescaler_TypeDef Prescaler, TIM6_PSCReloadMode_TypeDef TIM6_PSCReloadMode); 259 | void TIM6_ARRPreloadConfig(FunctionalState NewState); 260 | void TIM6_SetCounter(uint8_t Counter); 261 | void TIM6_SetAutoreload(uint8_t Autoreload); 262 | uint8_t TIM6_GetCounter(void); 263 | TIM6_Prescaler_TypeDef TIM6_GetPrescaler(void); 264 | void TIM6_ITConfig(TIM6_IT_TypeDef TIM6_IT, FunctionalState NewState); 265 | void TIM6_ClearFlag(TIM6_FLAG_TypeDef TIM6_FLAG); 266 | ITStatus TIM6_GetITStatus(TIM6_IT_TypeDef TIM6_IT); 267 | void TIM6_GenerateEvent(TIM6_EventSource_TypeDef TIM6_EventSource); 268 | FlagStatus TIM6_GetFlagStatus(TIM6_FLAG_TypeDef TIM6_FLAG); 269 | void TIM6_ClearITPendingBit(TIM6_IT_TypeDef TIM6_IT); 270 | void TIM6_SelectOutputTrigger(TIM6_TRGOSource_TypeDef TIM6_TRGOSource); 271 | void TIM6_SelectMasterSlaveMode(FunctionalState NewState); 272 | void TIM6_SelectInputTrigger(TIM6_TS_TypeDef TIM6_InputTriggerSource); 273 | void TIM6_InternalClockConfig(void); 274 | void TIM6_SelectSlaveMode(TIM6_SlaveMode_TypeDef TIM6_SlaveMode); 275 | 276 | /** 277 | * @} 278 | */ 279 | 280 | #endif /* __STM8S_TIM6_H */ 281 | 282 | /** 283 | * @} 284 | */ 285 | 286 | 287 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 288 | -------------------------------------------------------------------------------- /include/stm8s_uart1.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_uart1.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototypes and macros for the UART1 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_UART1_H 30 | #define __STM8S_UART1_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup UART1_Exported_Types 42 | * @{ 43 | */ 44 | 45 | 46 | /** 47 | * @brief UART1 Irda Modes 48 | */ 49 | 50 | typedef enum { UART1_IRDAMODE_NORMAL = (uint8_t)0x00, /**< 0x00 Irda Normal Mode */ 51 | UART1_IRDAMODE_LOWPOWER = (uint8_t)0x01 /**< 0x01 Irda Low Power Mode */ 52 | } UART1_IrDAMode_TypeDef; 53 | 54 | /** 55 | * @brief UART1 WakeUP Modes 56 | */ 57 | typedef enum { UART1_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake up */ 58 | UART1_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark wake up */ 59 | } UART1_WakeUp_TypeDef; 60 | 61 | /** 62 | * @brief UART1 LIN Break detection length possible values 63 | */ 64 | typedef enum { UART1_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 0x01 10 bits Lin Break detection */ 65 | UART1_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 0x02 11 bits Lin Break detection */ 66 | } UART1_LINBreakDetectionLength_TypeDef; 67 | 68 | /** 69 | * @brief UART1 stop bits possible values 70 | */ 71 | 72 | typedef enum { UART1_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is transmitted at the end of frame*/ 73 | UART1_STOPBITS_0_5 = (uint8_t)0x10, /**< Half stop bits is transmitted at the end of frame*/ 74 | UART1_STOPBITS_2 = (uint8_t)0x20, /**< Two stop bits are transmitted at the end of frame*/ 75 | UART1_STOPBITS_1_5 = (uint8_t)0x30 /**< One and half stop bits*/ 76 | } UART1_StopBits_TypeDef; 77 | 78 | /** 79 | * @brief UART1 parity possible values 80 | */ 81 | typedef enum { UART1_PARITY_NO = (uint8_t)0x00, /**< No Parity*/ 82 | UART1_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/ 83 | UART1_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/ 84 | } UART1_Parity_TypeDef; 85 | 86 | /** 87 | * @brief UART1 Synchrone modes 88 | */ 89 | typedef enum { UART1_SYNCMODE_CLOCK_DISABLE = (uint8_t)0x80, /**< 0x80 Sync mode Disable, SLK pin Disable */ 90 | UART1_SYNCMODE_CLOCK_ENABLE = (uint8_t)0x08, /**< 0x08 Sync mode Enable, SLK pin Enable */ 91 | UART1_SYNCMODE_CPOL_LOW = (uint8_t)0x40, /**< 0x40 Steady low value on SCLK pin outside transmission window */ 92 | UART1_SYNCMODE_CPOL_HIGH = (uint8_t)0x04, /**< 0x04 Steady high value on SCLK pin outside transmission window */ 93 | UART1_SYNCMODE_CPHA_MIDDLE = (uint8_t)0x20, /**< 0x20 SCLK clock line activated in middle of data bit */ 94 | UART1_SYNCMODE_CPHA_BEGINING = (uint8_t)0x02, /**< 0x02 SCLK clock line activated at beginning of data bit */ 95 | UART1_SYNCMODE_LASTBIT_DISABLE = (uint8_t)0x10, /**< 0x10 The clock pulse of the last data bit is not output to the SCLK pin */ 96 | UART1_SYNCMODE_LASTBIT_ENABLE = (uint8_t)0x01 /**< 0x01 The clock pulse of the last data bit is output to the SCLK pin */ 97 | } UART1_SyncMode_TypeDef; 98 | 99 | /** 100 | * @brief UART1 Word length possible values 101 | */ 102 | typedef enum { UART1_WORDLENGTH_8D = (uint8_t)0x00,/**< 0x00 8 bits Data */ 103 | UART1_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data */ 104 | } UART1_WordLength_TypeDef; 105 | 106 | /** 107 | * @brief UART1 Mode possible values 108 | */ 109 | typedef enum { UART1_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable */ 110 | UART1_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable */ 111 | UART1_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Transmit Disable */ 112 | UART1_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire Half-duplex mode */ 113 | UART1_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Transmit Enable and Receive Enable */ 114 | } UART1_Mode_TypeDef; 115 | 116 | /** 117 | * @brief UART1 Flag possible values 118 | */ 119 | typedef enum { UART1_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */ 120 | UART1_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */ 121 | UART1_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */ 122 | UART1_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */ 123 | UART1_FLAG_OR = (uint16_t)0x0008, /*!< OverRun error flag */ 124 | UART1_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */ 125 | UART1_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */ 126 | UART1_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */ 127 | UART1_FLAG_LBDF = (uint16_t)0x0210, /*!< Line Break Detection Flag */ 128 | UART1_FLAG_SBK = (uint16_t)0x0101 /*!< Send Break characters Flag */ 129 | } UART1_Flag_TypeDef; 130 | 131 | /** 132 | * @brief UART1 Interrupt definition 133 | * UART1_IT possible values 134 | * Elements values convention: 0xZYX 135 | * X: Position of the corresponding Interrupt 136 | * - For the following values, X means the interrupt position in the CR2 register. 137 | * UART1_IT_TXE 138 | * UART1_IT_TC 139 | * UART1_IT_RXNE 140 | * UART1_IT_IDLE 141 | * UART1_IT_OR 142 | * - For the UART1_IT_PE value, X means the flag position in the CR1 register. 143 | * - For the UART1_IT_LBDF value, X means the flag position in the CR4 register. 144 | * Y: Flag position 145 | * - For the following values, Y means the flag (pending bit) position in the SR register. 146 | * UART1_IT_TXE 147 | * UART1_IT_TC 148 | * UART1_IT_RXNE 149 | * UART1_IT_IDLE 150 | * UART1_IT_OR 151 | * UART1_IT_PE 152 | * - For the UART1_IT_LBDF value, Y means the flag position in the CR4 register. 153 | * Z: Register index: indicate in which register the dedicated interrupt source is: 154 | * - 1==> CR1 register 155 | * - 2==> CR2 register 156 | * - 3==> CR4 register 157 | */ 158 | typedef enum { UART1_IT_TXE = (uint16_t)0x0277, /*!< Transmit interrupt */ 159 | UART1_IT_TC = (uint16_t)0x0266, /*!< Transmission Complete interrupt */ 160 | UART1_IT_RXNE = (uint16_t)0x0255, /*!< Receive interrupt */ 161 | UART1_IT_IDLE = (uint16_t)0x0244, /*!< IDLE line interrupt */ 162 | UART1_IT_OR = (uint16_t)0x0235, /*!< Overrun Error interrupt */ 163 | UART1_IT_PE = (uint16_t)0x0100, /*!< Parity Error interrupt */ 164 | UART1_IT_LBDF = (uint16_t)0x0346, /**< LIN break detection interrupt */ 165 | UART1_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt */ 166 | } UART1_IT_TypeDef; 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | /* Exported constants --------------------------------------------------------*/ 173 | /* Exported macros ------------------------------------------------------------*/ 174 | 175 | /* Private macros ------------------------------------------------------------*/ 176 | 177 | /** @addtogroup UART1_Private_Macros 178 | * @{ 179 | */ 180 | 181 | /** 182 | * @brief Macro used by the assert function to check the different functions parameters. 183 | */ 184 | 185 | /** 186 | * @brief Macro used by the assert_param function in order to check the different 187 | * sensitivity values for the MODEs possible combination should be one of 188 | * the following 189 | */ 190 | #define IS_UART1_MODE_OK(Mode) \ 191 | (((Mode) == (uint8_t)UART1_MODE_RX_ENABLE) || \ 192 | ((Mode) == (uint8_t)UART1_MODE_RX_DISABLE) || \ 193 | ((Mode) == (uint8_t)UART1_MODE_TX_ENABLE) || \ 194 | ((Mode) == (uint8_t)UART1_MODE_TX_DISABLE) || \ 195 | ((Mode) == (uint8_t)UART1_MODE_TXRX_ENABLE) || \ 196 | ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_ENABLE)) || \ 197 | ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_ENABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \ 198 | ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_DISABLE)) || \ 199 | ((Mode) == (uint8_t)((uint8_t)UART1_MODE_TX_DISABLE|(uint8_t)UART1_MODE_RX_ENABLE))) 200 | 201 | /** 202 | * @brief Macro used by the assert_param function in order to check the different 203 | * sensitivity values for the WordLengths 204 | */ 205 | #define IS_UART1_WORDLENGTH_OK(WordLength) \ 206 | (((WordLength) == UART1_WORDLENGTH_8D) || \ 207 | ((WordLength) == UART1_WORDLENGTH_9D)) 208 | 209 | /** 210 | * @brief Macro used by the assert_param function in order to check the different 211 | * sensitivity values for the SyncModes; it should exclude values such 212 | * as UART1_CLOCK_ENABLE|UART1_CLOCK_DISABLE 213 | */ 214 | #define IS_UART1_SYNCMODE_OK(SyncMode) \ 215 | (!((((SyncMode)&(((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLOCK_DISABLE))) == (((uint8_t)UART1_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART1_SYNCMODE_CLOCK_DISABLE))) \ 216 | || (((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPOL_LOW )|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) == (((uint8_t)UART1_SYNCMODE_CPOL_LOW )|((uint8_t)UART1_SYNCMODE_CPOL_HIGH))) \ 217 | ||(((SyncMode)&(((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPHA_BEGINING))) == (((uint8_t)UART1_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART1_SYNCMODE_CPHA_BEGINING))) \ 218 | || (((SyncMode)&(((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_LASTBIT_ENABLE))) == (((uint8_t)UART1_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART1_SYNCMODE_LASTBIT_ENABLE))))) 219 | 220 | /** 221 | * @brief Macro used by the assert_param function in order to check the different 222 | * sensitivity values for the FLAGs 223 | */ 224 | #define IS_UART1_FLAG_OK(Flag) \ 225 | (((Flag) == UART1_FLAG_TXE) || \ 226 | ((Flag) == UART1_FLAG_TC) || \ 227 | ((Flag) == UART1_FLAG_RXNE) || \ 228 | ((Flag) == UART1_FLAG_IDLE) || \ 229 | ((Flag) == UART1_FLAG_OR) || \ 230 | ((Flag) == UART1_FLAG_NF) || \ 231 | ((Flag) == UART1_FLAG_FE) || \ 232 | ((Flag) == UART1_FLAG_PE) || \ 233 | ((Flag) == UART1_FLAG_SBK) || \ 234 | ((Flag) == UART1_FLAG_LBDF)) 235 | /** 236 | * @brief Macro used by the assert_param function in order to check the different 237 | * sensitivity values for the FLAGs that can be cleared by writing 0 238 | */ 239 | #define IS_UART1_CLEAR_FLAG_OK(Flag) \ 240 | (((Flag) == UART1_FLAG_RXNE) || \ 241 | ((Flag) == UART1_FLAG_LBDF)) 242 | 243 | 244 | 245 | /** 246 | * @brief Macro used by the assert_param function in order to check the different 247 | * sensitivity values for the Interrupts 248 | */ 249 | 250 | #define IS_UART1_CONFIG_IT_OK(Interrupt) \ 251 | (((Interrupt) == UART1_IT_PE) || \ 252 | ((Interrupt) == UART1_IT_TXE) || \ 253 | ((Interrupt) == UART1_IT_TC) || \ 254 | ((Interrupt) == UART1_IT_RXNE_OR ) || \ 255 | ((Interrupt) == UART1_IT_IDLE) || \ 256 | ((Interrupt) == UART1_IT_LBDF)) 257 | 258 | /** 259 | * @brief Macro used by the assert function in order to check the different 260 | * sensitivity values for the pending bit 261 | */ 262 | #define IS_UART1_GET_IT_OK(ITPendingBit) \ 263 | (((ITPendingBit) == UART1_IT_TXE) || \ 264 | ((ITPendingBit) == UART1_IT_TC) || \ 265 | ((ITPendingBit) == UART1_IT_RXNE) || \ 266 | ((ITPendingBit) == UART1_IT_IDLE) || \ 267 | ((ITPendingBit) == UART1_IT_OR) || \ 268 | ((ITPendingBit) == UART1_IT_LBDF) || \ 269 | ((ITPendingBit) == UART1_IT_PE)) 270 | 271 | /** 272 | * @brief Macro used by the assert function in order to check the different 273 | * sensitivity values for the pending bit that can be cleared by writing 0 274 | */ 275 | #define IS_UART1_CLEAR_IT_OK(ITPendingBit) \ 276 | (((ITPendingBit) == UART1_IT_RXNE) || \ 277 | ((ITPendingBit) == UART1_IT_LBDF)) 278 | 279 | 280 | /** 281 | * @brief Macro used by the assert_param function in order to check the different 282 | * sensitivity values for the IrDAModes 283 | */ 284 | #define IS_UART1_IRDAMODE_OK(IrDAMode) \ 285 | (((IrDAMode) == UART1_IRDAMODE_LOWPOWER) || \ 286 | ((IrDAMode) == UART1_IRDAMODE_NORMAL)) 287 | 288 | /** 289 | * @brief Macro used by the assert_param function in order to check the different 290 | * sensitivity values for the WakeUps 291 | */ 292 | #define IS_UART1_WAKEUP_OK(WakeUp) \ 293 | (((WakeUp) == UART1_WAKEUP_IDLELINE) || \ 294 | ((WakeUp) == UART1_WAKEUP_ADDRESSMARK)) 295 | 296 | /** 297 | * @brief Macro used by the assert_param function in order to check the different 298 | * sensitivity values for the LINBreakDetectionLengths 299 | */ 300 | #define IS_UART1_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLength) \ 301 | (((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_10BITS) || \ 302 | ((LINBreakDetectionLength) == UART1_LINBREAKDETECTIONLENGTH_11BITS)) 303 | 304 | /** 305 | * @brief Macro used by the assert_param function in order to check the different 306 | * sensitivity values for the UART1_StopBits 307 | */ 308 | #define IS_UART1_STOPBITS_OK(StopBit) (((StopBit) == UART1_STOPBITS_1) || \ 309 | ((StopBit) == UART1_STOPBITS_0_5) || \ 310 | ((StopBit) == UART1_STOPBITS_2) || \ 311 | ((StopBit) == UART1_STOPBITS_1_5 )) 312 | 313 | /** 314 | * @brief Macro used by the assert_param function in order to check the different 315 | * sensitivity values for the Parity 316 | */ 317 | #define IS_UART1_PARITY_OK(Parity) (((Parity) == UART1_PARITY_NO) || \ 318 | ((Parity) == UART1_PARITY_EVEN) || \ 319 | ((Parity) == UART1_PARITY_ODD )) 320 | 321 | /** 322 | * @brief Macro used by the assert_param function in order to check the maximum 323 | * baudrate value 324 | */ 325 | #define IS_UART1_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000) 326 | 327 | 328 | /** 329 | * @brief Macro used by the assert_param function in order to check the address 330 | * of the UART1 or UART node 331 | */ 332 | #define UART1_ADDRESS_MAX ((uint8_t)16) 333 | #define IS_UART1_ADDRESS_OK(node) ((node) < UART1_ADDRESS_MAX ) 334 | 335 | /** 336 | * @} 337 | */ 338 | 339 | /* Exported functions ------------------------------------------------------- */ 340 | 341 | /** @addtogroup UART1_Exported_Functions 342 | * @{ 343 | */ 344 | 345 | void UART1_DeInit(void); 346 | void UART1_Init(uint32_t BaudRate, UART1_WordLength_TypeDef WordLength, 347 | UART1_StopBits_TypeDef StopBits, UART1_Parity_TypeDef Parity, 348 | UART1_SyncMode_TypeDef SyncMode, UART1_Mode_TypeDef Mode); 349 | void UART1_Cmd(FunctionalState NewState); 350 | void UART1_ITConfig(UART1_IT_TypeDef UART1_IT, FunctionalState NewState); 351 | void UART1_HalfDuplexCmd(FunctionalState NewState); 352 | void UART1_IrDAConfig(UART1_IrDAMode_TypeDef UART1_IrDAMode); 353 | void UART1_IrDACmd(FunctionalState NewState); 354 | void UART1_LINBreakDetectionConfig(UART1_LINBreakDetectionLength_TypeDef UART1_LINBreakDetectionLength); 355 | void UART1_LINCmd(FunctionalState NewState); 356 | void UART1_SmartCardCmd(FunctionalState NewState); 357 | void UART1_SmartCardNACKCmd(FunctionalState NewState); 358 | void UART1_WakeUpConfig(UART1_WakeUp_TypeDef UART1_WakeUp); 359 | void UART1_ReceiverWakeUpCmd(FunctionalState NewState); 360 | uint8_t UART1_ReceiveData8(void); 361 | uint16_t UART1_ReceiveData9(void); 362 | void UART1_SendData8(uint8_t Data); 363 | void UART1_SendData9(uint16_t Data); 364 | void UART1_SendBreak(void); 365 | void UART1_SetAddress(uint8_t UART1_Address); 366 | void UART1_SetGuardTime(uint8_t UART1_GuardTime); 367 | void UART1_SetPrescaler(uint8_t UART1_Prescaler); 368 | FlagStatus UART1_GetFlagStatus(UART1_Flag_TypeDef UART1_FLAG); 369 | void UART1_ClearFlag(UART1_Flag_TypeDef UART1_FLAG); 370 | ITStatus UART1_GetITStatus(UART1_IT_TypeDef UART1_IT); 371 | void UART1_ClearITPendingBit(UART1_IT_TypeDef UART1_IT); 372 | 373 | /** 374 | * @} 375 | */ 376 | 377 | #endif /* __STM8S_UART1_H */ 378 | 379 | /** 380 | * @} 381 | */ 382 | 383 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 384 | -------------------------------------------------------------------------------- /include/stm8s_uart3.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_uart3.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototypes and macros for the UART3 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_UART3_H 30 | #define __STM8S_UART3_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup UART3_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief UART3 WakeUP Modes 47 | */ 48 | typedef enum { UART3_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake up*/ 49 | UART3_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark wake up*/ 50 | } UART3_WakeUp_TypeDef; 51 | 52 | /** 53 | * @brief UART3 LIN Break detection length possible values 54 | */ 55 | typedef enum { UART3_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 10 bits Lin Break detection */ 56 | UART3_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 11 bits Lin Break detection */ 57 | } UART3_LINBreakDetectionLength_TypeDef; 58 | 59 | 60 | /** 61 | * @brief UART3 stop bits possible values 62 | */ 63 | typedef enum { UART3_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is transmitted at the end of frame*/ 64 | UART3_STOPBITS_2 = (uint8_t)0x20 /**< Two stop bits are transmitted at the end of frame*/ 65 | } UART3_StopBits_TypeDef; 66 | 67 | /** 68 | * @brief UART3 parity possible values 69 | */ 70 | typedef enum { UART3_PARITY_NO = (uint8_t)0x00, /**< No Parity*/ 71 | UART3_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/ 72 | UART3_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/ 73 | } UART3_Parity_TypeDef; 74 | 75 | /** 76 | * @brief UART3 Word length possible values 77 | */ 78 | typedef enum { UART3_WORDLENGTH_8D = (uint8_t)0x00, /**< 0x00 8 bits Data*/ 79 | UART3_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data*/ 80 | } UART3_WordLength_TypeDef; 81 | 82 | /** 83 | * @brief UART3 Mode Transmit/Receive possible values 84 | */ 85 | typedef enum { UART3_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable*/ 86 | UART3_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable*/ 87 | UART3_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Receive Enable*/ 88 | UART3_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire Half-duplex mode*/ 89 | UART3_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Receive Enable and Transmit enable*/ 90 | } UART3_Mode_TypeDef; 91 | 92 | /** 93 | * @brief UART3 Mode possible values 94 | */ 95 | typedef enum { UART3_LIN_MODE_MASTER = (uint8_t)0x00, /**< LIN Master Mode*/ 96 | UART3_LIN_MODE_SLAVE = (uint8_t)0x01 /**< LIN Slave Mode*/ 97 | } UART3_LinMode_TypeDef; 98 | /** 99 | * @brief UART3 automatic resynchronisation possible values 100 | */ 101 | typedef enum { UART3_LIN_AUTOSYNC_DISABLE = (uint8_t)0x00, /**< LIN Autosynchronization Disable*/ 102 | UART3_LIN_AUTOSYNC_ENABLE = (uint8_t)0x01 /**< LIN Autosynchronization Enable*/ 103 | } UART3_LinAutosync_TypeDef; 104 | /** 105 | * @brief UART3 Divider Update Method possible values 106 | */ 107 | typedef enum { UART3_LIN_DIVUP_LBRR1 = (uint8_t)0x00, /**< LIN LDIV is updated as soon as LBRR1 is written*/ 108 | UART3_LIN_DIVUP_NEXTRXNE = (uint8_t)0x01 /**< LIN LDIV is updated at the next received character*/ 109 | } UART3_LinDivUp_TypeDef; 110 | 111 | 112 | /** 113 | * @brief UART3 Flag possible values 114 | */ 115 | typedef enum 116 | { 117 | UART3_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */ 118 | UART3_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */ 119 | UART3_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */ 120 | UART3_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */ 121 | UART3_FLAG_OR_LHE = (uint16_t)0x0008, /*!< OverRun error flag */ 122 | UART3_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */ 123 | UART3_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */ 124 | UART3_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */ 125 | UART3_FLAG_SBK = (uint16_t)0x0101, /**< Send Break Complete interrupt flag */ 126 | UART3_FLAG_LBDF = (uint16_t)0x0210, /**< LIN Break Detection Flag */ 127 | UART3_FLAG_LHDF = (uint16_t)0x0302, /**< LIN Header Detection Flag*/ 128 | UART3_FLAG_LSF = (uint16_t)0x0301 /**< LIN Sync Field Flag*/ 129 | } UART3_Flag_TypeDef; 130 | 131 | /** 132 | * @brief UART3 Interrupt definition 133 | * UART3_IT possible values 134 | * Elements values convention: 0xZYX 135 | * X: Position of the corresponding Interrupt 136 | * - For the following values, X means the interrupt position in the CR2 register. 137 | * UART3_IT_TXE 138 | * UART3_IT_TC 139 | * UART3_IT_RXNE 140 | * UART3_IT_IDLE 141 | * UART3_IT_OR 142 | * - For the UART3_IT_PE value, X means the flag position in the CR1 register. 143 | * - For the UART3_IT_LBDF value, X means the flag position in the CR4 register. 144 | * - For the UART3_IT_LHDF value, X means the flag position in the CR6 register. 145 | * Y: Flag position 146 | * - For the following values, Y means the flag (pending bit) position in the SR register. 147 | * UART3_IT_TXE 148 | * UART3_IT_TC 149 | * UART3_IT_RXNE 150 | * UART3_IT_IDLE 151 | * UART3_IT_OR 152 | * UART3_IT_PE 153 | * - For the UART3_IT_LBDF value, Y means the flag position in the CR4 register. 154 | * - For the UART3_IT_LHDF value, Y means the flag position in the CR6 register. 155 | * Z: Register index: indicate in which register the dedicated interrupt source is: 156 | * - 1==> CR1 register 157 | * - 2==> CR2 register 158 | * - 3==> CR4 register 159 | * - 4==> CR6 register 160 | */ 161 | typedef enum { UART3_IT_TXE = (uint16_t)0x0277, /**< Transmit interrupt */ 162 | UART3_IT_TC = (uint16_t)0x0266, /**< Transmission Complete interrupt */ 163 | UART3_IT_RXNE = (uint16_t)0x0255, /**< Data Register Not Empty interrupt */ 164 | UART3_IT_IDLE = (uint16_t)0x0244, /**< Idle line detected interrupt */ 165 | UART3_IT_OR = (uint16_t)0x0235, /**< OverRun error interrupt */ 166 | UART3_IT_PE = (uint16_t)0x0100, /**< Parity Error interrupt */ 167 | UART3_IT_LBDF = (uint16_t)0x0346, /**< LIN Break Detection interrupt */ 168 | UART3_IT_LHDF = (uint16_t)0x0412, /**< LIN Header Detection interrupt*/ 169 | UART3_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt */ 170 | } UART3_IT_TypeDef; 171 | 172 | 173 | /** 174 | * @} 175 | */ 176 | 177 | /* Exported constants --------------------------------------------------------*/ 178 | /* Exported macros ------------------------------------------------------------*/ 179 | 180 | /* Private macros ------------------------------------------------------------*/ 181 | 182 | /** @addtogroup UART3_Private_Macros 183 | * @{ 184 | */ 185 | 186 | /** 187 | * @brief Macro used by the assert_param function in order to check the 188 | * different sensitivity values for the FLAGs 189 | */ 190 | #define IS_UART3_FLAG_OK(Flag) \ 191 | (((Flag) == UART3_FLAG_TXE) || \ 192 | ((Flag) == UART3_FLAG_TC) || \ 193 | ((Flag) == UART3_FLAG_RXNE) || \ 194 | ((Flag) == UART3_FLAG_IDLE) || \ 195 | ((Flag) == UART3_FLAG_OR_LHE) || \ 196 | ((Flag) == UART3_FLAG_NF) || \ 197 | ((Flag) == UART3_FLAG_FE) || \ 198 | ((Flag) == UART3_FLAG_PE) || \ 199 | ((Flag) == UART3_FLAG_SBK) || \ 200 | ((Flag) == UART3_FLAG_LSF) || \ 201 | ((Flag) == UART3_FLAG_LHDF) || \ 202 | ((Flag) == UART3_FLAG_LBDF)) 203 | 204 | 205 | /** 206 | * @brief Macro used by the assert_param function in order to check the 207 | * different sensitivity values for the FLAGs that can be cleared by writing 0 208 | */ 209 | #define IS_UART3_CLEAR_FLAG_OK(Flag) \ 210 | (((Flag) == UART3_FLAG_RXNE) || \ 211 | ((Flag) == UART3_FLAG_LHDF) || \ 212 | ((Flag) == UART3_FLAG_LSF) || \ 213 | ((Flag) == UART3_FLAG_LBDF)) 214 | 215 | /** 216 | * @brief Macro used by the assert_param function in order to check the 217 | * different sensitivity values for the Interrupts 218 | */ 219 | 220 | #define IS_UART3_CONFIG_IT_OK(Interrupt) \ 221 | (((Interrupt) == UART3_IT_PE) || \ 222 | ((Interrupt) == UART3_IT_TXE) || \ 223 | ((Interrupt) == UART3_IT_TC) || \ 224 | ((Interrupt) == UART3_IT_RXNE_OR ) || \ 225 | ((Interrupt) == UART3_IT_IDLE) || \ 226 | ((Interrupt) == UART3_IT_LHDF) || \ 227 | ((Interrupt) == UART3_IT_LBDF)) 228 | 229 | /** 230 | * @brief Macro used by the assert function in order to check the different 231 | * sensitivity values for the pending bit 232 | */ 233 | #define IS_UART3_GET_IT_OK(ITPendingBit) \ 234 | (((ITPendingBit) == UART3_IT_TXE) || \ 235 | ((ITPendingBit) == UART3_IT_TC) || \ 236 | ((ITPendingBit) == UART3_IT_RXNE) || \ 237 | ((ITPendingBit) == UART3_IT_IDLE) || \ 238 | ((ITPendingBit) == UART3_IT_OR) || \ 239 | ((ITPendingBit) == UART3_IT_LBDF) || \ 240 | ((ITPendingBit) == UART3_IT_LHDF) || \ 241 | ((ITPendingBit) == UART3_IT_PE)) 242 | 243 | /** 244 | * @brief Macro used by the assert function in order to check the different 245 | * sensitivity values for the pending bit that can be cleared by writing 0 246 | */ 247 | #define IS_UART3_CLEAR_IT_OK(ITPendingBit) \ 248 | (((ITPendingBit) == UART3_IT_RXNE) || \ 249 | ((ITPendingBit) == UART3_IT_LHDF) || \ 250 | ((ITPendingBit) == UART3_IT_LBDF)) 251 | 252 | /** 253 | * @brief Macro used by the assert_param function in order to check the different 254 | * sensitivity values for the MODEs 255 | */ 256 | #define IS_UART3_MODE_OK(Mode) \ 257 | (((Mode) == (uint8_t)UART3_MODE_RX_ENABLE) || \ 258 | ((Mode) == (uint8_t)UART3_MODE_RX_DISABLE) || \ 259 | ((Mode) == (uint8_t)UART3_MODE_TX_ENABLE) || \ 260 | ((Mode) == (uint8_t)UART3_MODE_TX_DISABLE) || \ 261 | ((Mode) == (uint8_t)UART3_MODE_TXRX_ENABLE) || \ 262 | ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_ENABLE)) || \ 263 | ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_ENABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \ 264 | ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_DISABLE)) || \ 265 | ((Mode) == (uint8_t)((uint8_t)UART3_MODE_TX_DISABLE|(uint8_t)UART3_MODE_RX_ENABLE))) 266 | 267 | /** 268 | * @brief Macro used by the assert_param function in order to check the different 269 | * sensitivity values for the WordLengths 270 | */ 271 | #define IS_UART3_WORDLENGTH_OK(WordLength) \ 272 | (((WordLength) == UART3_WORDLENGTH_8D) || \ 273 | ((WordLength) == UART3_WORDLENGTH_9D)) 274 | 275 | 276 | /** 277 | * @brief Macro used by the assert_param function in order to check the different 278 | * sensitivity values for the WakeUps 279 | */ 280 | #define IS_UART3_WAKEUP_OK(WakeUpMode) \ 281 | (((WakeUpMode) == UART3_WAKEUP_IDLELINE) || \ 282 | ((WakeUpMode) == UART3_WAKEUP_ADDRESSMARK)) 283 | 284 | /** 285 | * @brief Macro used by the assert_param function in order to check the different 286 | * sensitivity values for the LINBreakDetectionLengths 287 | */ 288 | #define IS_UART3_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLengths) \ 289 | (((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_10BITS) || \ 290 | ((LINBreakDetectionLengths) == UART3_LINBREAKDETECTIONLENGTH_11BITS)) 291 | 292 | /** 293 | * @brief Macro used by the assert_param function in order to check the different 294 | * sensitivity values for the UART3_StopBits 295 | */ 296 | #define IS_UART3_STOPBITS_OK(StopBit) \ 297 | (((StopBit) == UART3_STOPBITS_1) || \ 298 | ((StopBit) == UART3_STOPBITS_2)) 299 | 300 | /** 301 | * @brief Macro used by the assert_param function in order to check the different 302 | * sensitivity values for the Parity 303 | */ 304 | #define IS_UART3_PARITY_OK(Parity) \ 305 | (((Parity) == UART3_PARITY_NO) || \ 306 | ((Parity) == UART3_PARITY_EVEN) || \ 307 | ((Parity) == UART3_PARITY_ODD )) 308 | 309 | /** 310 | * @brief Macro used by the assert_param function in order to check the maximum 311 | * baudrate value 312 | */ 313 | #define IS_UART3_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000) 314 | 315 | /** 316 | * @brief Macro used by the assert_param function in order to check the address 317 | * of the UART3 or UART node 318 | */ 319 | #define UART3_ADDRESS_MAX ((uint8_t)16) 320 | #define IS_UART3_ADDRESS_OK(Node) ((Node) < UART3_ADDRESS_MAX) 321 | 322 | /** 323 | * @brief Macro used by the assert_param function in order to check the LIN mode 324 | */ 325 | #define IS_UART3_SLAVE_OK(Mode) \ 326 | (((Mode) == UART3_LIN_MODE_MASTER) || \ 327 | ((Mode) == UART3_LIN_MODE_SLAVE)) 328 | 329 | /** 330 | * @brief Macro used by the assert_param function in order to check the LIN 331 | * automatic resynchronization mode 332 | */ 333 | #define IS_UART3_AUTOSYNC_OK(AutosyncMode) \ 334 | (((AutosyncMode) == UART3_LIN_AUTOSYNC_ENABLE) || \ 335 | ((AutosyncMode) == UART3_LIN_AUTOSYNC_DISABLE)) 336 | 337 | /** 338 | * @brief Macro used by the assert_param function in order to check the LIN 339 | * divider update method 340 | */ 341 | #define IS_UART3_DIVUP_OK(DivupMethod) \ 342 | (((DivupMethod) == UART3_LIN_DIVUP_LBRR1) || \ 343 | ((DivupMethod) == UART3_LIN_DIVUP_NEXTRXNE)) 344 | 345 | /** 346 | * @} 347 | */ 348 | 349 | /* Exported functions ------------------------------------------------------- */ 350 | 351 | /** @addtogroup UART3_Exported_Functions 352 | * @{ 353 | */ 354 | 355 | void UART3_DeInit(void); 356 | void UART3_Init(uint32_t BaudRate, UART3_WordLength_TypeDef WordLength, 357 | UART3_StopBits_TypeDef StopBits, UART3_Parity_TypeDef Parity, 358 | UART3_Mode_TypeDef Mode); 359 | void UART3_Cmd(FunctionalState NewState); 360 | void UART3_ITConfig(UART3_IT_TypeDef UART3_IT, FunctionalState NewState); 361 | void UART3_LINBreakDetectionConfig(UART3_LINBreakDetectionLength_TypeDef UART3_LINBreakDetectionLength); 362 | void UART3_LINConfig(UART3_LinMode_TypeDef UART3_Mode, 363 | UART3_LinAutosync_TypeDef UART3_Autosync, 364 | UART3_LinDivUp_TypeDef UART3_DivUp); 365 | void UART3_LINCmd(FunctionalState NewState); 366 | void UART3_ReceiverWakeUpCmd(FunctionalState NewState); 367 | void UART3_WakeUpConfig( UART3_WakeUp_TypeDef UART3_WakeUp); 368 | uint8_t UART3_ReceiveData8(void); 369 | uint16_t UART3_ReceiveData9(void); 370 | void UART3_SendData8(uint8_t Data); 371 | void UART3_SendData9(uint16_t Data); 372 | void UART3_SendBreak(void); 373 | void UART3_SetAddress(uint8_t UART3_Address); 374 | FlagStatus UART3_GetFlagStatus(UART3_Flag_TypeDef UART3_FLAG); 375 | void UART3_ClearFlag(UART3_Flag_TypeDef UART3_FLAG); 376 | ITStatus UART3_GetITStatus(UART3_IT_TypeDef UART3_IT); 377 | void UART3_ClearITPendingBit(UART3_IT_TypeDef UART3_IT); 378 | /** 379 | * @} 380 | */ 381 | 382 | #endif /* __STM8S_UART3_H */ 383 | 384 | /** 385 | * @} 386 | */ 387 | 388 | 389 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 390 | -------------------------------------------------------------------------------- /include/stm8s_uart4.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_uart4.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototypes and macros for the UART4 peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_UART4_H 30 | #define __STM8S_UART4_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup UART4_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief UART4 Irda Modes 47 | */ 48 | 49 | typedef enum { UART4_IRDAMODE_NORMAL = (uint8_t)0x00, /**< 0x00 Irda Normal Mode */ 50 | UART4_IRDAMODE_LOWPOWER = (uint8_t)0x01 /**< 0x01 Irda Low Power Mode */ 51 | 52 | } UART4_IrDAMode_TypeDef; 53 | 54 | /** 55 | * @brief UART4 WakeUP Modes 56 | */ 57 | 58 | typedef enum { UART4_WAKEUP_IDLELINE = (uint8_t)0x00, /**< 0x01 Idle Line wake up */ 59 | UART4_WAKEUP_ADDRESSMARK = (uint8_t)0x08 /**< 0x02 Address Mark wake up */ 60 | } UART4_WakeUp_TypeDef; 61 | 62 | 63 | /** 64 | * @brief UART4 LIN Break detection length possible values 65 | */ 66 | typedef enum { UART4_LINBREAKDETECTIONLENGTH_10BITS = (uint8_t)0x00, /**< 0x01 10 bits Lin Break detection */ 67 | UART4_LINBREAKDETECTIONLENGTH_11BITS = (uint8_t)0x01 /**< 0x02 11 bits Lin Break detection */ 68 | } UART4_LINBreakDetectionLength_TypeDef; 69 | 70 | /** 71 | * @brief UART4 stop bits possible values 72 | */ 73 | 74 | typedef enum { UART4_STOPBITS_1 = (uint8_t)0x00, /**< One stop bit is transmitted at the end of frame*/ 75 | UART4_STOPBITS_0_5 = (uint8_t)0x10, /**< Half stop bits is transmitted at the end of frame*/ 76 | UART4_STOPBITS_2 = (uint8_t)0x20, /**< Two stop bits are transmitted at the end of frame*/ 77 | UART4_STOPBITS_1_5 = (uint8_t)0x30 /**< One and half stop bits*/ 78 | } UART4_StopBits_TypeDef; 79 | 80 | 81 | /** 82 | * @brief UART4 parity possible values 83 | */ 84 | typedef enum { UART4_PARITY_NO = (uint8_t)0x00, /**< No Parity*/ 85 | UART4_PARITY_EVEN = (uint8_t)0x04, /**< Even Parity*/ 86 | UART4_PARITY_ODD = (uint8_t)0x06 /**< Odd Parity*/ 87 | } UART4_Parity_TypeDef; 88 | /** 89 | * @brief UART4 Mode possible values 90 | */ 91 | typedef enum { UART4_LIN_MODE_MASTER = (uint8_t)0x00, /**< LIN Master Mode*/ 92 | UART4_LIN_MODE_SLAVE = (uint8_t)0x01 /**< LIN Slave Mode*/ 93 | } UART4_LinMode_TypeDef; 94 | /** 95 | * @brief UART4 automatic resynchronisation possible values 96 | */ 97 | typedef enum { UART4_LIN_AUTOSYNC_DISABLE = (uint8_t)0x00, /**< LIN Autosynchronization Disable*/ 98 | UART4_LIN_AUTOSYNC_ENABLE = (uint8_t)0x01 /**< LIN Autosynchronization Enable*/ 99 | } UART4_LinAutosync_TypeDef; 100 | /** 101 | * @brief UART4 Divider Update Method possible values 102 | */ 103 | typedef enum { UART4_LIN_DIVUP_LBRR1 = (uint8_t)0x00, /**< LIN LDIV is updated as soon as LBRR1 is written*/ 104 | UART4_LIN_DIVUP_NEXTRXNE = (uint8_t)0x01 /**< LIN LDIV is updated at the next received character*/ 105 | } UART4_LinDivUp_TypeDef; 106 | 107 | /** 108 | * @brief UART4 Synchrone modes 109 | */ 110 | typedef enum { UART4_SYNCMODE_CLOCK_DISABLE = (uint8_t)0x80, /**< 0x80 Sync mode Disable, SLK pin Disable */ 111 | UART4_SYNCMODE_CLOCK_ENABLE = (uint8_t)0x08, /**< 0x08 Sync mode Enable, SLK pin Enable */ 112 | UART4_SYNCMODE_CPOL_LOW = (uint8_t)0x40, /**< 0x40 Steady low value on SCLK pin outside transmission window */ 113 | UART4_SYNCMODE_CPOL_HIGH = (uint8_t)0x04, /**< 0x04 Steady high value on SCLK pin outside transmission window */ 114 | UART4_SYNCMODE_CPHA_MIDDLE = (uint8_t)0x20, /**< 0x20 SCLK clock line activated in middle of data bit */ 115 | UART4_SYNCMODE_CPHA_BEGINING = (uint8_t)0x02, /**< 0x02 SCLK clock line activated at beginning of data bit */ 116 | UART4_SYNCMODE_LASTBIT_DISABLE = (uint8_t)0x10, /**< 0x10 The clock pulse of the last data bit is not output to the SCLK pin */ 117 | UART4_SYNCMODE_LASTBIT_ENABLE = (uint8_t)0x01 /**< 0x01 The clock pulse of the last data bit is output to the SCLK pin */ 118 | } UART4_SyncMode_TypeDef; 119 | 120 | /** 121 | * @brief UART4 Word length possible values 122 | */ 123 | typedef enum { UART4_WORDLENGTH_8D = (uint8_t)0x00,/**< 0x00 8 bits Data */ 124 | UART4_WORDLENGTH_9D = (uint8_t)0x10 /**< 0x10 9 bits Data */ 125 | } UART4_WordLength_TypeDef; 126 | 127 | /** 128 | * @brief UART4 Mode possible values 129 | */ 130 | typedef enum { UART4_MODE_RX_ENABLE = (uint8_t)0x08, /**< 0x08 Receive Enable */ 131 | UART4_MODE_TX_ENABLE = (uint8_t)0x04, /**< 0x04 Transmit Enable */ 132 | UART4_MODE_TX_DISABLE = (uint8_t)0x80, /**< 0x80 Transmit Disable */ 133 | UART4_MODE_RX_DISABLE = (uint8_t)0x40, /**< 0x40 Single-wire Half-duplex mode */ 134 | UART4_MODE_TXRX_ENABLE = (uint8_t)0x0C /**< 0x0C Transmit Enable and Receive Enable */ 135 | } UART4_Mode_TypeDef; 136 | /** 137 | * @brief UART4 Flag possible values 138 | */ 139 | typedef enum 140 | { 141 | UART4_FLAG_TXE = (uint16_t)0x0080, /*!< Transmit Data Register Empty flag */ 142 | UART4_FLAG_TC = (uint16_t)0x0040, /*!< Transmission Complete flag */ 143 | UART4_FLAG_RXNE = (uint16_t)0x0020, /*!< Read Data Register Not Empty flag */ 144 | UART4_FLAG_IDLE = (uint16_t)0x0010, /*!< Idle line detected flag */ 145 | UART4_FLAG_OR_LHE = (uint16_t)0x0008, /*!< OverRun error flag */ 146 | UART4_FLAG_NF = (uint16_t)0x0004, /*!< Noise error flag */ 147 | UART4_FLAG_FE = (uint16_t)0x0002, /*!< Framing Error flag */ 148 | UART4_FLAG_PE = (uint16_t)0x0001, /*!< Parity Error flag */ 149 | UART4_FLAG_SBK = (uint16_t)0x0101, /**< Send Break Complete interrupt flag */ 150 | UART4_FLAG_LBDF = (uint16_t)0x0210, /**< LIN Break Detection Flag */ 151 | UART4_FLAG_LHDF = (uint16_t)0x0302, /**< LIN Header Detection Flag*/ 152 | UART4_FLAG_LSF = (uint16_t)0x0301 /**< LIN Sync Field Flag*/ 153 | } UART4_Flag_TypeDef; 154 | 155 | /** 156 | * @brief UART4 Interrupt definition 157 | * UART4_IT possible values 158 | * Elements values convention: 0xZYX 159 | * X: Position of the corresponding Interrupt 160 | * - For the following values, X means the interrupt position in the CR2 register. 161 | * UART4_IT_TXE 162 | * UART4_IT_TC 163 | * UART4_IT_RXNE 164 | * UART4_IT_IDLE 165 | * UART4_IT_OR 166 | * - For the UART4_IT_PE value, X means the flag position in the CR1 register. 167 | * - For the UART4_IT_LBDF value, X means the flag position in the CR4 register. 168 | * - For the UART4_IT_LHDF value, X means the flag position in the CR6 register. 169 | * Y: Flag position 170 | * - For the following values, Y means the flag (pending bit) position in the SR register. 171 | * UART4_IT_TXE 172 | * UART4_IT_TC 173 | * UART4_IT_RXNE 174 | * UART4_IT_IDLE 175 | * UART4_IT_OR 176 | * UART4_IT_PE 177 | * - For the UART4_IT_LBDF value, Y means the flag position in the CR4 register. 178 | * - For the UART4_IT_LHDF value, Y means the flag position in the CR6 register. 179 | * Z: Register index: indicate in which register the dedicated interrupt source is: 180 | * - 1==> CR1 register 181 | * - 2==> CR2 register 182 | * - 3==> CR4 register 183 | * - 4==> CR6 register 184 | */ 185 | typedef enum { UART4_IT_TXE = (uint16_t)0x0277, /**< Transmit interrupt */ 186 | UART4_IT_TC = (uint16_t)0x0266, /**< Transmission Complete interrupt */ 187 | UART4_IT_RXNE = (uint16_t)0x0255, /**< Data Register Not Empty interrupt */ 188 | UART4_IT_IDLE = (uint16_t)0x0244, /**< Idle line detected interrupt */ 189 | UART4_IT_OR = (uint16_t)0x0235, /**< OverRun error interrupt */ 190 | UART4_IT_PE = (uint16_t)0x0100, /**< Parity Error interrupt */ 191 | UART4_IT_LBDF = (uint16_t)0x0346, /**< LIN Break Detection interrupt */ 192 | UART4_IT_LHDF = (uint16_t)0x0412, /**< LIN Header Detection interrupt*/ 193 | UART4_IT_RXNE_OR = (uint16_t)0x0205 /*!< Receive/Overrun interrupt */ 194 | } UART4_IT_TypeDef; 195 | 196 | /** 197 | * @} 198 | */ 199 | 200 | /* Exported constants --------------------------------------------------------*/ 201 | /* Exported macros -----------------------------------------------------------*/ 202 | /* Private macros ------------------------------------------------------------*/ 203 | 204 | /** @addtogroup UART4_Private_Macros 205 | * @{ 206 | */ 207 | 208 | /** 209 | * @brief Macro used by the assert function to check the different functions parameters. 210 | */ 211 | 212 | /** 213 | * @brief Macro used by the assert_param function in order to check the different 214 | * sensitivity values for the MODEs possible combination should be one of 215 | * the following. 216 | */ 217 | 218 | #define IS_UART4_MODE_OK(Mode) \ 219 | (((Mode) == (uint8_t)UART4_MODE_RX_ENABLE) || \ 220 | ((Mode) == (uint8_t)UART4_MODE_RX_DISABLE) || \ 221 | ((Mode) == (uint8_t)UART4_MODE_TX_ENABLE) || \ 222 | ((Mode) == (uint8_t)UART4_MODE_TX_DISABLE) || \ 223 | ((Mode) == (uint8_t)UART4_MODE_TXRX_ENABLE) || \ 224 | ((Mode) == (uint8_t)((uint8_t)UART4_MODE_TX_ENABLE|(uint8_t)UART4_MODE_RX_ENABLE)) || \ 225 | ((Mode) == (uint8_t)((uint8_t)UART4_MODE_TX_ENABLE|(uint8_t)UART4_MODE_RX_DISABLE)) || \ 226 | ((Mode) == (uint8_t)((uint8_t)UART4_MODE_TX_DISABLE|(uint8_t)UART4_MODE_RX_DISABLE)) || \ 227 | ((Mode) == (uint8_t)((uint8_t)UART4_MODE_TX_DISABLE|(uint8_t)UART4_MODE_RX_ENABLE))) 228 | 229 | /** 230 | * @brief Macro used by the assert_param function in order to check the different 231 | * sensitivity values for the WordLengths 232 | */ 233 | #define IS_UART4_WORDLENGTH_OK(WordLength) \ 234 | (((WordLength) == UART4_WORDLENGTH_8D) || \ 235 | ((WordLength) == UART4_WORDLENGTH_9D)) 236 | 237 | /** 238 | * @brief Macro used by the assert_param function in order to check the different 239 | * sensitivity values for the SyncModes; it should exclude values such 240 | * as UART4_CLOCK_ENABLE|UART4_CLOCK_DISABLE 241 | */ 242 | #define IS_UART4_SYNCMODE_OK(SyncMode) \ 243 | (!((((SyncMode)&(((uint8_t)UART4_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART4_SYNCMODE_CLOCK_DISABLE))) == (((uint8_t)UART4_SYNCMODE_CLOCK_ENABLE)|((uint8_t)UART4_SYNCMODE_CLOCK_DISABLE))) || \ 244 | (((SyncMode)&(((uint8_t)UART4_SYNCMODE_CPOL_LOW )|((uint8_t)UART4_SYNCMODE_CPOL_HIGH))) == (((uint8_t)UART4_SYNCMODE_CPOL_LOW )|((uint8_t)UART4_SYNCMODE_CPOL_HIGH))) || \ 245 | (((SyncMode)&(((uint8_t)UART4_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART4_SYNCMODE_CPHA_BEGINING))) == (((uint8_t)UART4_SYNCMODE_CPHA_MIDDLE)|((uint8_t)UART4_SYNCMODE_CPHA_BEGINING))) || \ 246 | (((SyncMode)&(((uint8_t)UART4_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART4_SYNCMODE_LASTBIT_ENABLE))) == (((uint8_t)UART4_SYNCMODE_LASTBIT_DISABLE)|((uint8_t)UART4_SYNCMODE_LASTBIT_ENABLE))))) 247 | 248 | /** 249 | * @brief Macro used by the assert_param function in order to check the 250 | * different sensitivity values for the FLAGs 251 | */ 252 | #define IS_UART4_FLAG_OK(Flag) \ 253 | (((Flag) == UART4_FLAG_TXE) || \ 254 | ((Flag) == UART4_FLAG_TC) || \ 255 | ((Flag) == UART4_FLAG_RXNE) || \ 256 | ((Flag) == UART4_FLAG_IDLE) || \ 257 | ((Flag) == UART4_FLAG_OR_LHE) || \ 258 | ((Flag) == UART4_FLAG_NF) || \ 259 | ((Flag) == UART4_FLAG_FE) || \ 260 | ((Flag) == UART4_FLAG_PE) || \ 261 | ((Flag) == UART4_FLAG_SBK) || \ 262 | ((Flag) == UART4_FLAG_LSF) || \ 263 | ((Flag) == UART4_FLAG_LHDF) || \ 264 | ((Flag) == UART4_FLAG_LBDF)) 265 | 266 | 267 | /** 268 | * @brief Macro used by the assert_param function in order to check the 269 | * different sensitivity values for the FLAGs that can be cleared by writing 0 270 | */ 271 | #define IS_UART4_CLEAR_FLAG_OK(Flag) \ 272 | (((Flag) == UART4_FLAG_RXNE) || \ 273 | ((Flag) == UART4_FLAG_LHDF) || \ 274 | ((Flag) == UART4_FLAG_LSF) || \ 275 | ((Flag) == UART4_FLAG_LBDF)) 276 | 277 | /** 278 | * @brief Macro used by the assert_param function in order to check 279 | * the different sensitivity values for the Interrupts 280 | */ 281 | 282 | #define IS_UART4_CONFIG_IT_OK(Interrupt) \ 283 | (((Interrupt) == UART4_IT_PE) || \ 284 | ((Interrupt) == UART4_IT_TXE) || \ 285 | ((Interrupt) == UART4_IT_TC) || \ 286 | ((Interrupt) == UART4_IT_RXNE_OR ) || \ 287 | ((Interrupt) == UART4_IT_IDLE) || \ 288 | ((Interrupt) == UART4_IT_LHDF) || \ 289 | ((Interrupt) == UART4_IT_LBDF)) 290 | 291 | /** 292 | * @brief Macro used by the assert function in order to check the different 293 | * sensitivity values for the pending bit 294 | */ 295 | #define IS_UART4_GET_IT_OK(ITPendingBit) \ 296 | (((ITPendingBit) == UART4_IT_TXE) || \ 297 | ((ITPendingBit) == UART4_IT_TC) || \ 298 | ((ITPendingBit) == UART4_IT_RXNE) || \ 299 | ((ITPendingBit) == UART4_IT_IDLE) || \ 300 | ((ITPendingBit) == UART4_IT_OR) || \ 301 | ((ITPendingBit) == UART4_IT_LBDF) || \ 302 | ((ITPendingBit) == UART4_IT_LHDF) || \ 303 | ((ITPendingBit) == UART4_IT_PE)) 304 | 305 | /** 306 | * @brief Macro used by the assert function in order to check the different 307 | * sensitivity values for the pending bit that can be cleared by writing 0 308 | */ 309 | #define IS_UART4_CLEAR_IT_OK(ITPendingBit) \ 310 | (((ITPendingBit) == UART4_IT_RXNE) || \ 311 | ((ITPendingBit) == UART4_IT_LHDF) || \ 312 | ((ITPendingBit) == UART4_IT_LBDF)) 313 | 314 | 315 | /** 316 | * @brief Macro used by the assert_param function in order to check the different 317 | * sensitivity values for the IrDAModes 318 | */ 319 | #define IS_UART4_IRDAMODE_OK(IrDAMode) \ 320 | (((IrDAMode) == UART4_IRDAMODE_LOWPOWER) || \ 321 | ((IrDAMode) == UART4_IRDAMODE_NORMAL)) 322 | 323 | /** 324 | * @brief Macro used by the assert_param function in order to check the different 325 | * sensitivity values for the WakeUps 326 | */ 327 | #define IS_UART4_WAKEUP_OK(WakeUp) \ 328 | (((WakeUp) == UART4_WAKEUP_IDLELINE) || \ 329 | ((WakeUp) == UART4_WAKEUP_ADDRESSMARK)) 330 | 331 | /** 332 | * @brief Macro used by the assert_param function in order to check the different 333 | * sensitivity values for the LINBreakDetectionLengths 334 | */ 335 | #define IS_UART4_LINBREAKDETECTIONLENGTH_OK(LINBreakDetectionLength) \ 336 | (((LINBreakDetectionLength) == UART4_LINBREAKDETECTIONLENGTH_10BITS) || \ 337 | ((LINBreakDetectionLength) == UART4_LINBREAKDETECTIONLENGTH_11BITS)) 338 | 339 | /** 340 | * @brief Macro used by the assert_param function in order to check the different 341 | * sensitivity values for the UART4_StopBits 342 | */ 343 | #define IS_UART4_STOPBITS_OK(StopBit) (((StopBit) == UART4_STOPBITS_1) || \ 344 | ((StopBit) == UART4_STOPBITS_0_5) || \ 345 | ((StopBit) == UART4_STOPBITS_2) || \ 346 | ((StopBit) == UART4_STOPBITS_1_5 )) 347 | 348 | /** 349 | * @brief Macro used by the assert_param function in order to check the different 350 | * sensitivity values for the Paritys 351 | */ 352 | #define IS_UART4_PARITY_OK(Parity) (((Parity) == UART4_PARITY_NO) || \ 353 | ((Parity) == UART4_PARITY_EVEN) || \ 354 | ((Parity) == UART4_PARITY_ODD )) 355 | 356 | /** 357 | * @brief Macro used by the assert_param function in order to check the maximum 358 | * baudrate value 359 | */ 360 | #define IS_UART4_BAUDRATE_OK(NUM) ((NUM) <= (uint32_t)625000) 361 | 362 | /** 363 | * @brief Macro used by the assert_param function in order to check the address 364 | * of the UART4 or UART node 365 | */ 366 | #define UART4_ADDRESS_MAX ((uint8_t)16) 367 | #define IS_UART4_ADDRESS_OK(node) ((node) < UART4_ADDRESS_MAX ) 368 | 369 | /** 370 | * @brief Macro used by the assert_param function in order to check the LIN mode 371 | */ 372 | #define IS_UART4_SLAVE_OK(Mode) \ 373 | (((Mode) == UART4_LIN_MODE_MASTER) || \ 374 | ((Mode) == UART4_LIN_MODE_SLAVE)) 375 | 376 | /** 377 | * @brief Macro used by the assert_param function in order to check the LIN 378 | * automatic resynchronization mode 379 | */ 380 | #define IS_UART4_AUTOSYNC_OK(AutosyncMode) \ 381 | (((AutosyncMode) == UART4_LIN_AUTOSYNC_ENABLE) || \ 382 | ((AutosyncMode) == UART4_LIN_AUTOSYNC_DISABLE)) 383 | 384 | /** 385 | * @brief Macro used by the assert_param function in order to check the LIN divider update method 386 | */ 387 | #define IS_UART4_DIVUP_OK(DivupMethod) \ 388 | (((DivupMethod) == UART4_LIN_DIVUP_LBRR1) || \ 389 | ((DivupMethod) == UART4_LIN_DIVUP_NEXTRXNE)) 390 | 391 | 392 | /** 393 | * @} 394 | */ 395 | 396 | /* Exported functions ------------------------------------------------------- */ 397 | 398 | /** @addtogroup UART4_Exported_Functions 399 | * @{ 400 | */ 401 | void UART4_DeInit(void); 402 | void UART4_Init(uint32_t BaudRate, UART4_WordLength_TypeDef WordLength, 403 | UART4_StopBits_TypeDef StopBits, UART4_Parity_TypeDef Parity, 404 | UART4_SyncMode_TypeDef SyncMode, UART4_Mode_TypeDef Mode); 405 | void UART4_Cmd(FunctionalState NewState); 406 | void UART4_ITConfig(UART4_IT_TypeDef UART4_IT, FunctionalState NewState); 407 | void UART4_HalfDuplexCmd(FunctionalState NewState); 408 | void UART4_IrDAConfig(UART4_IrDAMode_TypeDef UART4_IrDAMode); 409 | void UART4_IrDACmd(FunctionalState NewState); 410 | void UART4_LINBreakDetectionConfig(UART4_LINBreakDetectionLength_TypeDef UART4_LINBreakDetectionLength); 411 | void UART4_LINConfig(UART4_LinMode_TypeDef UART4_Mode, 412 | UART4_LinAutosync_TypeDef UART4_Autosync, 413 | UART4_LinDivUp_TypeDef UART4_DivUp); 414 | void UART4_LINCmd(FunctionalState NewState); 415 | void UART4_SmartCardCmd(FunctionalState NewState); 416 | void UART4_SmartCardNACKCmd(FunctionalState NewState); 417 | void UART4_WakeUpConfig(UART4_WakeUp_TypeDef UART4_WakeUp); 418 | void UART4_ReceiverWakeUpCmd(FunctionalState NewState); 419 | uint8_t UART4_ReceiveData8(void); 420 | uint16_t UART4_ReceiveData9(void); 421 | void UART4_SendData8(uint8_t Data); 422 | void UART4_SendData9(uint16_t Data); 423 | void UART4_SendBreak(void); 424 | void UART4_SetAddress(uint8_t UART4_Address); 425 | void UART4_SetGuardTime(uint8_t UART4_GuardTime); 426 | void UART4_SetPrescaler(uint8_t UART4_Prescaler); 427 | FlagStatus UART4_GetFlagStatus(UART4_Flag_TypeDef UART4_FLAG); 428 | void UART4_ClearFlag(UART4_Flag_TypeDef UART4_FLAG); 429 | ITStatus UART4_GetITStatus(UART4_IT_TypeDef UART4_IT); 430 | void UART4_ClearITPendingBit(UART4_IT_TypeDef UART4_IT); 431 | 432 | 433 | /** 434 | * @} 435 | */ 436 | 437 | #endif /* __STM8S_UART4_H */ 438 | 439 | /** 440 | * @} 441 | */ 442 | 443 | 444 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 445 | -------------------------------------------------------------------------------- /include/stm8s_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_wwdg.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the WWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_WWDG_H 30 | #define __STM8S_WWDG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Private macros ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup WWDG_Private_Macros 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief Macro used by the assert function in order to check the 47 | * values of the window register. 48 | */ 49 | #define IS_WWDG_WINDOWLIMITVALUE_OK(WindowLimitValue) ((WindowLimitValue) <= 0x7F) 50 | 51 | /** 52 | * @brief Macro used by the assert function in order to check the different 53 | * values of the counter register. 54 | */ 55 | #define IS_WWDG_COUNTERVALUE_OK(CounterValue) ((CounterValue) <= 0x7F) 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /* Exported types ------------------------------------------------------------*/ 62 | 63 | /* Exported functions ------------------------------------------------------- */ 64 | 65 | /** @addtogroup WWDG_Exported_Functions 66 | * @{ 67 | */ 68 | 69 | void WWDG_Init(uint8_t Counter, uint8_t WindowValue); 70 | void WWDG_SetCounter(uint8_t Counter); 71 | uint8_t WWDG_GetCounter(void); 72 | void WWDG_SWReset(void); 73 | void WWDG_SetWindowValue(uint8_t WindowValue); 74 | 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | #endif /* __STM8S_WWDG_H */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | --------------------------------------------------------------------------------