1 /***************************************************************************** 2 * Copyright (c) 2022, Nations Technologies Inc. 3 * 4 * All rights reserved. 5 * **************************************************************************** 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * - Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the disclaimer below. 12 * 13 * Nations' name may not be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 19 * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 22 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * ****************************************************************************/ 27 28 /** 29 * @file n32l43x_lpuart.h 30 * @author Nations 31 * @version v1.2.0 32 * 33 * @copyright Copyright (c) 2022, Nations Technologies Inc. All rights reserved. 34 */ 35 #ifndef __N32L43X_LPUART_H__ 36 #define __N32L43X_LPUART_H__ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #include "n32l43x.h" 43 44 /** @addtogroup n32l43x_StdPeriph_Driver 45 * @{ 46 */ 47 48 /** @addtogroup LPUART 49 * @{ 50 */ 51 52 /** @addtogroup LPUART_Exported_Types 53 * @{ 54 */ 55 56 /** 57 * @brief LPUART Init Structure definition 58 */ 59 60 typedef struct 61 { 62 uint32_t BaudRate; /*!< This member configures the LPUART communication baud rate. 63 The baud rate is computed using the following formula: 64 - IntegerDivider = ((CLK) / (LPUART_InitStruct->BaudRate))) 65 - FractionalDivider */ 66 67 uint16_t Parity; /*!< Specifies the parity mode. 68 This parameter can be a value of @ref Parity 69 @note When parity is enabled, the computed parity is inserted 70 at the MSB position of the transmitted data (only support 71 8 data bits). */ 72 73 uint16_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. 74 This parameter can be a value of @ref Mode */ 75 76 uint16_t RtsThreshold; /* Specifies RTS Threshold. 77 This parameter can be a value of @ref RtsThreshold */ 78 79 uint16_t HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled 80 or disabled. 81 This parameter can be a value of @ref LPUART_Hardware_Flow_Control */ 82 } LPUART_InitType; 83 84 /** 85 * @} 86 */ 87 88 /** @addtogroup LPUART_Exported_Constants 89 * @{ 90 */ 91 92 /** @addtogroup Parity 93 * @{ 94 */ 95 96 #define LPUART_PE_NO ((uint16_t)0x0008) 97 #define LPUART_PE_EVEN ((uint16_t)0x0000) 98 #define LPUART_PE_ODD ((uint16_t)0x0001) 99 #define IS_LPUART_PARITY(PARITY) (((PARITY) == LPUART_PE_NO) || ((PARITY) == LPUART_PE_EVEN) || ((PARITY) == LPUART_PE_ODD)) 100 /** 101 * @} 102 */ 103 104 /** @addtogroup Mode 105 * @{ 106 */ 107 108 #define LPUART_MODE_RX ((uint16_t)0x0000) 109 #define LPUART_MODE_TX ((uint16_t)0x0002) 110 #define IS_LPUART_MODE(MODE) (((MODE) == LPUART_MODE_RX) || ((MODE) == LPUART_MODE_TX)) 111 /** 112 * @} 113 */ 114 115 /** @addtogroup RtsThreshold 116 * @{ 117 */ 118 119 #define LPUART_RTSTH_FIFOHF ((uint16_t)0x0000) 120 #define LPUART_RTSTH_FIFO3QF ((uint16_t)0x0100) 121 #define LPUART_RTSTH_FIFOFU ((uint16_t)0x0200) 122 #define IS_LPUART_RTSTHRESHOLD(RTSTHRESHOLD) \ 123 (((RTSTHRESHOLD) == LPUART_RTSTH_FIFOHF) || ((RTSTHRESHOLD) == LPUART_RTSTH_FIFO3QF) || ((RTSTHRESHOLD) == LPUART_RTSTH_FIFOFU)) 124 /** 125 * @} 126 */ 127 128 /** @addtogroup Hardware_Flow_Control 129 * @{ 130 */ 131 #define LPUART_HFCTRL_NONE ((uint16_t)0x0000) 132 #define LPUART_HFCTRL_CTS ((uint16_t)0x0400) 133 #define LPUART_HFCTRL_RTS ((uint16_t)0x0800) 134 #define LPUART_HFCTRL_RTS_CTS ((uint16_t)0x0C00) 135 #define IS_LPUART_HARDWARE_FLOW_CONTROL(CONTROL) \ 136 (((CONTROL) == LPUART_HFCTRL_NONE) || ((CONTROL) == LPUART_HFCTRL_RTS) || ((CONTROL) == LPUART_HFCTRL_CTS) \ 137 || ((CONTROL) == LPUART_HFCTRL_RTS_CTS)) 138 /** 139 * @} 140 */ 141 142 /** @addtogroup LPUART_Interrupt_definition 143 * @{ 144 */ 145 146 #define LPUART_INT_PE ((uint16_t)0x0001) 147 #define LPUART_INT_TXC ((uint16_t)0x0102) 148 #define LPUART_INT_FIFO_OV ((uint16_t)0x0204) 149 #define LPUART_INT_FIFO_FU ((uint16_t)0x0308) 150 #define LPUART_INT_FIFO_HF ((uint16_t)0x0410) 151 #define LPUART_INT_FIFO_NE ((uint16_t)0x0520) 152 #define LPUART_INT_WUF ((uint16_t)0x0640) 153 #define IS_LPUART_CFG_INT(IT) \ 154 (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ 155 || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) 156 #define IS_LPUART_GET_INT(IT) \ 157 (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ 158 || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) 159 #define IS_LPUART_CLR_INT(IT) \ 160 (((IT) == LPUART_INT_PE) || ((IT) == LPUART_INT_TXC) || ((IT) == LPUART_INT_FIFO_OV) || ((IT) == LPUART_INT_FIFO_FU) \ 161 || ((IT) == LPUART_INT_FIFO_HF) || ((IT) == LPUART_INT_FIFO_NE) || ((IT) == LPUART_INT_WUF)) 162 /** 163 * @} 164 */ 165 166 /** @addtogroup LPUART_DMA_Requests 167 * @{ 168 */ 169 170 #define LPUART_DMAREQ_TX ((uint16_t)0x0020) 171 #define LPUART_DMAREQ_RX ((uint16_t)0x0040) 172 #define IS_LPUART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF9F) == (uint16_t)0x00) && ((DMAREQ) != (uint16_t)0x00)) 173 174 /** 175 * @} 176 */ 177 178 /** @addtogroup LPUART_WakeUp_methods 179 * @{ 180 */ 181 182 #define LPUART_WUSTP_STARTBIT ((uint16_t)0x0000) 183 #define LPUART_WUSTP_RXNE ((uint16_t)0x1000) 184 #define LPUART_WUSTP_BYTE ((uint16_t)0x2000) 185 #define LPUART_WUSTP_FRAME ((uint16_t)0x3000) 186 #define IS_LPUART_WAKEUP(WAKEUP) \ 187 (((WAKEUP) == LPUART_WUSTP_STARTBIT) || ((WAKEUP) == LPUART_WUSTP_RXNE) || ((WAKEUP) == LPUART_WUSTP_BYTE) || ((WAKEUP) == LPUART_WUSTP_FRAME)) 188 /** 189 * @} 190 */ 191 192 /** @addtogroup LPUART_Sampling_methods 193 * @{ 194 */ 195 196 #define LPUART_SMPCNT_3B ((uint16_t)0x0000) 197 #define LPUART_SMPCNT_1B ((uint16_t)0x4000) 198 #define IS_LPUART_SAMPLING(SAMPLING) (((SAMPLING) == LPUART_SMPCNT_1B) || ((SAMPLING) == LPUART_SMPCNT_3B)) 199 /** 200 * @} 201 */ 202 203 /** @addtogroup LPUART_Flags 204 * @{ 205 */ 206 207 #define LPUART_FLAG_PEF ((uint16_t)0x0001) 208 #define LPUART_FLAG_TXC ((uint16_t)0x0002) 209 #define LPUART_FLAG_FIFO_OV ((uint16_t)0x0004) 210 #define LPUART_FLAG_FIFO_FU ((uint16_t)0x0008) 211 #define LPUART_FLAG_FIFO_HF ((uint16_t)0x0010) 212 #define LPUART_FLAG_FIFO_NE ((uint16_t)0x0020) 213 #define LPUART_FLAG_CTS ((uint16_t)0x0040) 214 #define LPUART_FLAG_WUF ((uint16_t)0x0080) 215 #define LPUART_FLAG_NF ((uint16_t)0x0100) 216 #define IS_LPUART_FLAG(FLAG) \ 217 (((FLAG) == LPUART_FLAG_PEF) || ((FLAG) == LPUART_FLAG_TXC) || ((FLAG) == LPUART_FLAG_FIFO_OV) \ 218 || ((FLAG) == LPUART_FLAG_FIFO_FU) || ((FLAG) == LPUART_FLAG_FIFO_HF) || ((FLAG) == LPUART_FLAG_FIFO_NE) \ 219 || ((FLAG) == LPUART_FLAG_CTS) || ((FLAG) == LPUART_FLAG_WUF) || ((FLAG) == LPUART_FLAG_NF)) 220 221 #define IS_LPUART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFE40) == 0x00) && ((FLAG) != (uint16_t)0x00)) 222 223 #define IS_LPUART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x010000)) 224 225 #define IS_LPUART_DATA(DATA) ((DATA) <= 0xFF) 226 227 /** 228 * @} 229 */ 230 231 /** 232 * @} 233 */ 234 235 /** @addtogroup LPUART_Exported_Macros 236 * @{ 237 */ 238 239 /** 240 * @} 241 */ 242 243 /** @addtogroup LPUART_Exported_Functions 244 * @{ 245 */ 246 247 void LPUART_DeInit(void); 248 void LPUART_Init(LPUART_InitType* LPUART_InitStruct); 249 void LPUART_StructInit(LPUART_InitType* LPUART_InitStruct); 250 void LPUART_FlushRxFifo(void); 251 void LPUART_ConfigInt(uint16_t LPUART_INT, FunctionalState Cmd); 252 void LPUART_EnableDMA(uint16_t LPUART_DMAReq, FunctionalState Cmd); 253 void LPUART_ConfigWakeUpMethod(uint16_t LPUART_WakeUpMethod); 254 void LPUART_EnableWakeUpStop(FunctionalState Cmd); 255 void LPUART_ConfigSamplingMethod(uint16_t LPUART_SamplingMethod); 256 void LPUART_EnableLoopBack(FunctionalState Cmd); 257 void LPUART_SendData(uint8_t Data); 258 uint8_t LPUART_ReceiveData(void); 259 void LPUART_ConfigWakeUpData(uint32_t LPUART_WakeUpData); 260 FlagStatus LPUART_GetFlagStatus(uint16_t LPUART_FLAG); 261 void LPUART_ClrFlag(uint16_t LPUART_FLAG); 262 INTStatus LPUART_GetIntStatus(uint16_t LPUART_INT); 263 void LPUART_ClrIntPendingBit(uint16_t LPART_INT); 264 265 #ifdef __cplusplus 266 } 267 #endif 268 269 #endif /* __N32L43X_LPUART_H__ */ 270 /** 271 * @} 272 */ 273 274 /** 275 * @} 276 */ 277 278 /** 279 * @} 280 */ 281