1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #ifndef S7816_H_ 19 #define S7816_H_ 20 21 #include "gpio.h" 22 #include "stimer.h" 23 #include "uart.h" 24 25 #define s7816_en(uart_num) uart_rtx_en(uart_num) 26 #define s7816_set_rtx_pin(s7816_trx_pin) uart_set_rtx_pin(s7816_trx_pin) 27 28 /** 29 * @brief Define 7816 TRX pin. 30 */ 31 typedef enum { 32 S7816_UART0_RTX_A4 = GPIO_PA4, 33 S7816_UART0_RTX_B3 = GPIO_PB3, 34 S7816_UART0_RTX_D3 = GPIO_PD3, 35 36 S7816_UART1_RTX_C7 = GPIO_PC7, 37 S7816_UART1_RTX_D7 = GPIO_PD7, 38 S7816_UART1_RTX_E2 = GPIO_PE2, 39 } s7816_rtx_pin_e; 40 41 /** 42 * @brief Define 7816 clock. 43 */ 44 typedef enum { 45 S7816_4MHZ = 4, 46 S7816_6MHZ = 6, 47 S7816_12MHZ = 12, 48 } s7816_clock_e; 49 50 /** 51 * @brief Define 7816 clk pin. 52 */ 53 typedef enum { 54 S7817_CLK_PA0 = GPIO_PA0, 55 } s7816_clk_pin_e; 56 57 /** 58 * @brief This function is used to set the s7816 clock. 59 * @param[in] div - set the divider of clock of 7816 module. 60 * @return none. 61 * @note system clk is 24MHZ 62 * 7816clk: 0x60-4Mhz 0x40-6Mhz 0x20-12Mhz 63 * baudrate: 0x60-10752 0x40-16194 0x20-32388 64 * the clk-pin is PA0 by default. 65 */ 66 extern void s7816_set_clk(unsigned char div); 67 68 /** 69 * @brief This function is used to initialize the s7816 module. 70 * @param[in] uart_num - UART0 or UART1. 71 * @param[in] clock - the clock of s7816. 72 * @param[in] f - the clock frequency conversion factor of s7816. 73 * @param[in] d - the bitrate regulator of s7816. 74 * @return none. 75 */ 76 extern void s7816_init(uart_num_e uart_num, s7816_clock_e clock, int f, int d); 77 78 /** 79 * @brief This function is used to active the IC card,set the trx pin and coldreset. 80 * @param[in] none. 81 * @return none. 82 */ 83 extern void s7816_coldreset(void); 84 85 /** 86 * @brief This function is used to set all the pin of s7816 module. 87 * @param[in] rst_pin - the rst pin of s7816. 88 * @param[in] vcc_pin - the vcc pin of s7816. 89 * @param[in] clk_pin - the clk pin of s7816. 90 * @param[in] trx_pin - the trx pin of s7816. 91 * @return none. 92 */ 93 extern void s7816_set_pin(gpio_pin_e rst_pin, gpio_pin_e vcc_pin, s7816_clk_pin_e clk_pin, s7816_rtx_pin_e trx_pin); 94 95 /** 96 * @brief This function is used to release the trigger 97 * @param[in] none. 98 * @return none. 99 */ 100 extern void s7816_release_trig(void); 101 102 /** 103 * @brief This function is used to set the RST pin of s7816. 104 * @param[in] pin_7816_rst - the RST pin of s7816. 105 * @return none. 106 */ 107 extern void s7816_set_rst_pin(gpio_pin_e pin_7816_rst); 108 109 /** 110 * @brief This function is used to set the VCC pin of s7816. 111 * @param[in] pin_7816_vcc - the VCC pin of s7816. 112 * @return none. 113 */ 114 extern void s7816_set_vcc_pin(gpio_pin_e pin_7816_vcc); 115 116 /** 117 * @brief This function is used to warmreset. 118 * @param[in] none. 119 * @return none. 120 * @note the warmreset is required after the IC-CARD active. 121 */ 122 extern void s7816_warmreset(void); 123 124 /** 125 * @brief This function is used to set the rst-wait time of the s7816 module. 126 * @param[in] rst_time_us - set the s7816_rst_time. 127 * @param[in] atr_time_us - set the s7816_atr_time. 128 * @return none. 129 */ 130 extern void s7816_set_time(int rst_time_us, int atr_time_us); 131 132 /** 133 * @brief This function is used to warmreset. 134 * @param[in] uart_num - UART0 or UART1. 135 * @param[in] tx_data - the data need to send. 136 * return none. 137 */ 138 extern void s7816_send_byte(uart_num_e uart_num, unsigned char tx_data); 139 140 #endif /* S7816_H_ */ 141