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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define C4X4KEY_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
75 #define C4X4KEY_RETVAL uint8_t
76 
77 #define C4X4KEY_OK 0x00
78 #define C4X4KEY_INIT_ERROR 0xFF
79 
80 // Button value
81 
82 #define C4X4KEY_BUTTON_0 0xEFFF
83 #define C4X4KEY_BUTTON_1 0xFFFE
84 #define C4X4KEY_BUTTON_2 0xFFFD
85 #define C4X4KEY_BUTTON_3 0xFFFB
86 #define C4X4KEY_BUTTON_4 0xFFEF
87 #define C4X4KEY_BUTTON_5 0xFFDF
88 #define C4X4KEY_BUTTON_6 0xFFBF
89 #define C4X4KEY_BUTTON_7 0xFEFF
90 #define C4X4KEY_BUTTON_8 0xFDFF
91 #define C4X4KEY_BUTTON_9 0xFBFF
92 #define C4X4KEY_BUTTON_A 0xFFF7
93 #define C4X4KEY_BUTTON_B 0xFF7F
94 #define C4X4KEY_BUTTON_C 0xF7FF
95 #define C4X4KEY_BUTTON_D 0xBFFF
96 #define C4X4KEY_BUTTON_STAR 0x7FFF
97 #define C4X4KEY_BUTTON_HASH 0xDFFF
98 
99 
100 // Max 16-bit
101 
102 #define C4X4KEY_MAX_16_BIT 0xFFFF
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  digital_out_t cs;
118 
119  // Modules
120 
121  spi_master_t spi;
122  pin_name_t chip_select;
123 
124 } c4x4key_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t miso;
134  pin_name_t mosi;
135  pin_name_t sck;
136  pin_name_t cs;
137 
138  // static variable
139 
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
143 
144 } c4x4key_cfg_t;
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
166 
176 
188 void c4x4key_generic_transfer ( c4x4key_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
189 
198 uint16_t c4x4key_get_data ( c4x4key_t *ctx );
199 
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 #endif // _C4X4KEY_H_
215  // End public_function group
218 
219 // ------------------------------------------------------------------------- END
c4x4key_cfg_t::sck
pin_name_t sck
Definition: c4x4key.h:135
c4x4key_cfg_t
Click configuration structure definition.
Definition: c4x4key.h:130
c4x4key_t::spi
spi_master_t spi
Definition: c4x4key.h:121
C4X4KEY_RETVAL
#define C4X4KEY_RETVAL
Definition: c4x4key.h:75
c4x4key_cfg_t::cs
pin_name_t cs
Definition: c4x4key.h:136
c4x4key_cfg_t::spi_speed
uint32_t spi_speed
Definition: c4x4key.h:140
c4x4key_t::chip_select
pin_name_t chip_select
Definition: c4x4key.h:122
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:133
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:142
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:134
c4x4key_init
C4X4KEY_RETVAL c4x4key_init(c4x4key_t *ctx, c4x4key_cfg_t *cfg)
Initialization function.
c4x4key_t
Click ctx object definition.
Definition: c4x4key.h:116
c4x4key_t::cs
digital_out_t cs
Definition: c4x4key.h:117
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:141