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 // End group macro
96// --------------------------------------------------------------- PUBLIC TYPES
105typedef 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
119typedef 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
135 // End types group
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138
143#ifdef __cplusplus
144extern "C"{
145#endif
146
156
166
178void c4x4key_generic_transfer ( c4x4key_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
179
188uint16_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
#define C4X4KEY_RETVAL
Definition: c4x4key.h:65
C4X4KEY_RETVAL c4x4key_init(c4x4key_t *ctx, c4x4key_cfg_t *cfg)
Initialization function.
void c4x4key_cfg_setup(c4x4key_cfg_t *cfg)
Config Object Initialization function.
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.
uint8_t c4x4key_get_btn_position(c4x4key_t *ctx)
Get position pressed button function.
uint16_t c4x4key_get_data(c4x4key_t *ctx)
Get 16-bit data function.
Click configuration structure definition.
Definition: c4x4key.h:120
spi_master_chip_select_polarity_t cs_polarity
Definition: c4x4key.h:132
pin_name_t sck
Definition: c4x4key.h:125
spi_master_mode_t spi_mode
Definition: c4x4key.h:131
pin_name_t mosi
Definition: c4x4key.h:124
uint32_t spi_speed
Definition: c4x4key.h:130
pin_name_t miso
Definition: c4x4key.h:123
pin_name_t cs
Definition: c4x4key.h:126
Click ctx object definition.
Definition: c4x4key.h:106
digital_out_t cs
Definition: c4x4key.h:107
spi_master_t spi
Definition: c4x4key.h:111
pin_name_t chip_select
Definition: c4x4key.h:112