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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define C4X4KEY_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
65 #define C4X4KEY_RETVAL uint8_t
66 
67 #define C4X4KEY_OK 0x00
68 #define C4X4KEY_INIT_ERROR 0xFF
69 
70 // Button value
71 
72 #define C4X4KEY_BUTTON_0 0xEFFF
73 #define C4X4KEY_BUTTON_1 0xFFFE
74 #define C4X4KEY_BUTTON_2 0xFFFD
75 #define C4X4KEY_BUTTON_3 0xFFFB
76 #define C4X4KEY_BUTTON_4 0xFFEF
77 #define C4X4KEY_BUTTON_5 0xFFDF
78 #define C4X4KEY_BUTTON_6 0xFFBF
79 #define C4X4KEY_BUTTON_7 0xFEFF
80 #define C4X4KEY_BUTTON_8 0xFDFF
81 #define C4X4KEY_BUTTON_9 0xFBFF
82 #define C4X4KEY_BUTTON_A 0xFFF7
83 #define C4X4KEY_BUTTON_B 0xFF7F
84 #define C4X4KEY_BUTTON_C 0xF7FF
85 #define C4X4KEY_BUTTON_D 0xBFFF
86 #define C4X4KEY_BUTTON_STAR 0x7FFF
87 #define C4X4KEY_BUTTON_HASH 0xDFFF
88 
89 
90 // Max 16-bit
91 
92 #define C4X4KEY_MAX_16_BIT 0xFFFF
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
105 typedef struct
106 {
107  digital_out_t cs;
108 
109  // Modules
110 
111  spi_master_t spi;
112  pin_name_t chip_select;
113 
114 } c4x4key_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // static variable
129 
130  uint32_t spi_speed;
131  spi_master_mode_t spi_mode;
132  spi_master_chip_select_polarity_t cs_polarity;
133 
134 } c4x4key_cfg_t;
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
166 
178 void c4x4key_generic_transfer ( c4x4key_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
179 
188 uint16_t c4x4key_get_data ( c4x4key_t *ctx );
189 
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // _C4X4KEY_H_
205  // End public_function group
208 
209 // ------------------------------------------------------------------------- END
c4x4key_cfg_t::sck
pin_name_t sck
Definition: c4x4key.h:125
c4x4key_cfg_t
Click configuration structure definition.
Definition: c4x4key.h:120
c4x4key_t::spi
spi_master_t spi
Definition: c4x4key.h:111
C4X4KEY_RETVAL
#define C4X4KEY_RETVAL
Definition: c4x4key.h:65
c4x4key_cfg_t::cs
pin_name_t cs
Definition: c4x4key.h:126
c4x4key_cfg_t::spi_speed
uint32_t spi_speed
Definition: c4x4key.h:130
c4x4key_t::chip_select
pin_name_t chip_select
Definition: c4x4key.h:112
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:123
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:132
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:124
c4x4key_init
C4X4KEY_RETVAL c4x4key_init(c4x4key_t *ctx, c4x4key_cfg_t *cfg)
Initialization function.
c4x4key_t
Click ctx object definition.
Definition: c4x4key.h:106
c4x4key_t::cs
digital_out_t cs
Definition: c4x4key.h:107
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:131