c4x4key  2.0.0.0
c4x4key.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef C4X4KEY_H
36 #define C4X4KEY_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
67 #define C4X4KEY_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
79 #define C4X4KEY_RETVAL uint8_t
80 
81 #define C4X4KEY_OK 0x00
82 #define C4X4KEY_INIT_ERROR 0xFF
83 
84 // Button value
85 
86 #define C4X4KEY_BUTTON_0 0xEFFF
87 #define C4X4KEY_BUTTON_1 0xFFFE
88 #define C4X4KEY_BUTTON_2 0xFFFD
89 #define C4X4KEY_BUTTON_3 0xFFFB
90 #define C4X4KEY_BUTTON_4 0xFFEF
91 #define C4X4KEY_BUTTON_5 0xFFDF
92 #define C4X4KEY_BUTTON_6 0xFFBF
93 #define C4X4KEY_BUTTON_7 0xFEFF
94 #define C4X4KEY_BUTTON_8 0xFDFF
95 #define C4X4KEY_BUTTON_9 0xFBFF
96 #define C4X4KEY_BUTTON_A 0xFFF7
97 #define C4X4KEY_BUTTON_B 0xFF7F
98 #define C4X4KEY_BUTTON_C 0xF7FF
99 #define C4X4KEY_BUTTON_D 0xBFFF
100 #define C4X4KEY_BUTTON_STAR 0x7FFF
101 #define C4X4KEY_BUTTON_HASH 0xDFFF
102 
103 
104 // Max 16-bit
105 
106 #define C4X4KEY_MAX_16_BIT 0xFFFF
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
119 typedef struct
120 {
121  digital_out_t cs;
122 
123  // Modules
124 
125  spi_master_t spi;
126  pin_name_t chip_select;
127 
128 } c4x4key_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136 
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
141 
142  // static variable
143 
144  uint32_t spi_speed;
145  spi_master_mode_t spi_mode;
146  spi_master_chip_select_polarity_t cs_polarity;
147 
148 } c4x4key_cfg_t;
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
180 
192 void c4x4key_generic_transfer ( c4x4key_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
193 
202 uint16_t c4x4key_get_data ( c4x4key_t *ctx );
203 
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 #endif // _C4X4KEY_H_
219  // End public_function group
222 
223 // ------------------------------------------------------------------------- END
c4x4key_cfg_t::sck
pin_name_t sck
Definition: c4x4key.h:139
c4x4key_cfg_t
Click configuration structure definition.
Definition: c4x4key.h:134
c4x4key_t::spi
spi_master_t spi
Definition: c4x4key.h:125
C4X4KEY_RETVAL
#define C4X4KEY_RETVAL
Definition: c4x4key.h:79
c4x4key_cfg_t::cs
pin_name_t cs
Definition: c4x4key.h:140
c4x4key_cfg_t::spi_speed
uint32_t spi_speed
Definition: c4x4key.h:144
c4x4key_t::chip_select
pin_name_t chip_select
Definition: c4x4key.h:126
c4x4key_generic_transfer
void c4x4key_generic_transfer(c4x4key_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
c4x4key_cfg_t::miso
pin_name_t miso
Definition: c4x4key.h:137
c4x4key_get_btn_position
uint8_t c4x4key_get_btn_position(c4x4key_t *ctx)
Get position pressed button function.
c4x4key_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c4x4key.h:146
c4x4key_get_data
uint16_t c4x4key_get_data(c4x4key_t *ctx)
Get 16-bit data function.
c4x4key_cfg_t::mosi
pin_name_t mosi
Definition: c4x4key.h:138
c4x4key_init
C4X4KEY_RETVAL c4x4key_init(c4x4key_t *ctx, c4x4key_cfg_t *cfg)
Initialization function.
c4x4key_t
Click ctx object definition.
Definition: c4x4key.h:120
c4x4key_t::cs
digital_out_t cs
Definition: c4x4key.h:121
c4x4key_cfg_setup
void c4x4key_cfg_setup(c4x4key_cfg_t *cfg)
Config Object Initialization function.
c4x4key_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c4x4key.h:145