charger12 2.0.0.0
charger12.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 CHARGER12_H
36#define CHARGER12_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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define CHARGER12_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.che = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
75 cfg.vok = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define CHARGER12_RETVAL uint8_t
83
84#define CHARGER12_OK 0x00
85#define CHARGER12_INIT_ERROR 0xFF
92#define CHARGER12_SPI_VOLATILE_WIPER_0 0x00
93#define CHARGER12_SPI_VOLATILE_WIPER_1 0x01
94#define CHARGER12_SPI_NON_VOLATILE_WIPER_0 0x02
95#define CHARGER12_SPI_NON_VOLATILE_WIPER_1 0x03
96#define CHARGER12_SPI_VOLATILE_TCON 0x04
97#define CHARGER12_SPI_STATUS_REGISTER 0x05
98#define CHARGER12_SPI_DATA_EEPROM_0 0x06
99#define CHARGER12_SPI_DATA_EEPROM_1 0x07
100#define CHARGER12_SPI_DATA_EEPROM_2 0x08
101#define CHARGER12_SPI_DATA_EEPROM_3 0x09
102#define CHARGER12_SPI_DATA_EEPROM_4 0x0A
103#define CHARGER12_SPI_DATA_EEPROM_5 0x0B
104#define CHARGER12_SPI_DATA_EEPROM_6 0x0C
105#define CHARGER12_SPI_DATA_EEPROM_7 0x0D
106#define CHARGER12_SPI_DATA_EEPROM_8 0x0E
107#define CHARGER12_SPI_DATA_EEPROM_9 0x0F
114#define CHARGER12_MODE_Li 0
115#define CHARGER12_MODE_NiMh_NiCd 1
116#define CHARGER12_MODE_DISABLE 2
117#define CHARGER12_MODE_NO_BATTERY 3
120 // End group macro
121// --------------------------------------------------------------- PUBLIC TYPES
130typedef struct
131{
132 // Output pins
133
134 digital_out_t cs;
135 digital_out_t che;
136 digital_out_t mod;
137
138 // Input pins
139
140 digital_in_t vok;
141
142 // Modules
143
144 spi_master_t spi;
145 pin_name_t chip_select;
146
148
152typedef struct
153{
154 // Communication gpio pins
155
156 pin_name_t miso;
157 pin_name_t mosi;
158 pin_name_t sck;
159 pin_name_t cs;
160
161 // Additional gpio pins
162
163 pin_name_t che;
164 pin_name_t mod;
165 pin_name_t vok;
166
167 // static variable
168
169 uint32_t spi_speed;
170 spi_master_mode_t spi_mode;
171 spi_master_chip_select_polarity_t cs_polarity;
172
174
175 // End types group
176// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177
182#ifdef __cplusplus
183extern "C"{
184#endif
185
195
205
217void charger12_generic_transfer ( charger12_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t tx_len, uint8_t rx_len );
218
226
234void charger12_pwm_set ( charger12_t *ctx, uint8_t pin_state );
235
243void charger12_rst_set ( charger12_t *ctx, uint8_t pin_state );
244
252void charger12_cs_set ( charger12_t *ctx, uint8_t pin_state );
253
261uint8_t charger12_mode_select ( charger12_t *ctx, uint8_t mode_select );
262
271void charger12_spi_set_register( charger12_t *ctx, uint8_t register_address, uint16_t register_value );
272
280
288
289
290
291#ifdef __cplusplus
292}
293#endif
294#endif // _CHARGER12_H_
295
296 // End public_function group
298
299// ------------------------------------------------------------------------- END
#define CHARGER12_RETVAL
Definition charger12.h:82
void charger12_generic_transfer(charger12_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t tx_len, uint8_t rx_len)
Generic transfer function.
void charger12_rst_set(charger12_t *ctx, uint8_t pin_state)
Setting RST pin state.
void charger12_spi_decrement_wiper(charger12_t *ctx)
Decrementing wiper position.
void charger12_spi_increment_wiper(charger12_t *ctx)
Incrementing wiper position.
void charger12_spi_set_register(charger12_t *ctx, uint8_t register_address, uint16_t register_value)
Setting register.
uint8_t charger12_mode_select(charger12_t *ctx, uint8_t mode_select)
Selecting device operation mode.
void charger12_cs_set(charger12_t *ctx, uint8_t pin_state)
Setting CS pin state.
uint8_t charger12_int_get(charger12_t *ctx)
Getting INT pin state.
void charger12_pwm_set(charger12_t *ctx, uint8_t pin_state)
Setting PWM pin state.
CHARGER12_RETVAL charger12_init(charger12_t *ctx, charger12_cfg_t *cfg)
Initialization function.
void charger12_cfg_setup(charger12_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition charger12.h:153
spi_master_chip_select_polarity_t cs_polarity
Definition charger12.h:171
pin_name_t vok
Definition charger12.h:165
pin_name_t sck
Definition charger12.h:158
spi_master_mode_t spi_mode
Definition charger12.h:170
pin_name_t mod
Definition charger12.h:164
pin_name_t mosi
Definition charger12.h:157
uint32_t spi_speed
Definition charger12.h:169
pin_name_t che
Definition charger12.h:163
pin_name_t miso
Definition charger12.h:156
pin_name_t cs
Definition charger12.h:159
Click ctx object definition.
Definition charger12.h:131
digital_out_t cs
Definition charger12.h:134
digital_out_t mod
Definition charger12.h:136
spi_master_t spi
Definition charger12.h:144
digital_in_t vok
Definition charger12.h:140
pin_name_t chip_select
Definition charger12.h:145
digital_out_t che
Definition charger12.h:135