nanopower3  2.1.0.0
nanopower3.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef NANOPOWER3_H
29 #define NANOPOWER3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define NANOPOWER3_CMD_VREG 0x11
70 #define NANOPOWER3_CMD_NVREG 0x21
71 #define NANOPOWER3_CMD_VREGxNVREG 0x51
72 #define NANOPOWER3_CMD_NVREGxVREG 0x61
73 
78 #define NANOPOWER3_1V_OUT_VOLTAGE 0x00
79 #define NANOPOWER3_1V2_OUT_VOLTAGE 0x01
80 #define NANOPOWER3_1V5_OUT_VOLTAGE 0x02
81 #define NANOPOWER3_1V8_OUT_VOLTAGE 0x03
82 #define NANOPOWER3_2V_OUT_VOLTAGE 0x04
83 #define NANOPOWER3_2V5_OUT_VOLTAGE 0x05
84 #define NANOPOWER3_3V_OUT_VOLTAGE 0x06
85 #define NANOPOWER3_3V3_OUT_VOLTAGE 0x07
86 #define NANOPOWER3_3V5_OUT_VOLTAGE 0x08
87 #define NANOPOWER3_4V_OUT_VOLTAGE 0x09
88 #define NANOPOWER3_4V5_OUT_VOLTAGE 0x0A
89 
94 #define NANOPOWER3_1V_RESISTANCE 187000
95 #define NANOPOWER3_1V2_RESISTANCE 93100
96 #define NANOPOWER3_1V5_RESISTANCE 53600
97 #define NANOPOWER3_1V8_RESISTANCE 37400
98 #define NANOPOWER3_2V_RESISTANCE 29000
99 #define NANOPOWER3_2V5_RESISTANCE 20000
100 #define NANOPOWER3_3V_RESISTANCE 15000
101 #define NANOPOWER3_3V3_RESISTANCE 13100
102 #define NANOPOWER3_3V5_RESISTANCE 12200
103 #define NANOPOWER3_4V_RESISTANCE 10000
104 #define NANOPOWER3_4V5_RESISTANCE 9000
105 
110 #define NANOPOWER3_R11_RESISTANCE 7200
111 #define NANOPOWER3_DIGIPOT_MAX_RESISTANCE 200000
112 #define NANOPOWER3_DIGIPOT_MAX_VAL 255
113 #define NANOPOWER3_MAX_RESISTANCE 207200
114 #define NANOPOWER3_ROUND_TO_NEAREST_INT 0.5
115 
120 #define NANOPOWER3_PIN_STATE_HIGH 0x01
121 #define NANOPOWER3_PIN_STATE_LOW 0x00
122 
128 #define NANOPOWER3_DEVICE_ADDRESS_GND 0x28
129 #define NANOPOWER3_DEVICE_ADDRESS_VCC 0x29
130  // nanopower3_set
132 
147 #define NANOPOWER3_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
150  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
151  cfg.ctr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
152  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
153  // nanopower3_map // nanopower3
156 
161 typedef struct
162 {
163  // Output pins
164  digital_out_t ctr;
166  // Input pins
167  digital_in_t an;
168  digital_in_t pg;
170  // Modules
171  i2c_master_t i2c;
173  // I2C slave address
174  uint8_t slave_address;
176 } nanopower3_t;
177 
182 typedef struct
183 {
184  pin_name_t scl;
185  pin_name_t sda;
187  pin_name_t an;
188  pin_name_t ctr;
189  pin_name_t pg;
191  uint32_t i2c_speed;
192  uint8_t i2c_address;
195 
200 typedef enum
201 {
203  NANOPOWER3_ERROR = -1
204 
206 
223 
238 
252 
267 err_t nanopower3_generic_write ( nanopower3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
268 
283 err_t nanopower3_generic_read ( nanopower3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
284 
295 
306 
316 void nanopower3_set_ctr_pin ( nanopower3_t *ctx, uint8_t pin_state );
317 
330 err_t nanopower3_write_data ( nanopower3_t *ctx, uint8_t cmd, uint8_t data_in );
331 
343 err_t nanopower3_set_wiper_pos ( nanopower3_t *ctx, uint8_t wiper_pos );
344 
356 err_t nanopower3_set_resistance ( nanopower3_t *ctx, uint32_t resistance );
357 
369 err_t nanopower3_set_voltage ( nanopower3_t *ctx, uint8_t out_vol );
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // NANOPOWER3_H
375  // nanopower3
377 
378 // ------------------------------------------------------------------------ END
nanopower3_get_an_pin_state
uint8_t nanopower3_get_an_pin_state(nanopower3_t *ctx)
Nano Power 3 get AN pin state function.
nanopower3_set_voltage
err_t nanopower3_set_voltage(nanopower3_t *ctx, uint8_t out_vol)
Nano Power 3 set output voltage function.
nanopower3_cfg_t::an
pin_name_t an
Definition: nanopower3.h:187
nanopower3_cfg_t::i2c_address
uint8_t i2c_address
Definition: nanopower3.h:192
nanopower3_cfg_t::pg
pin_name_t pg
Definition: nanopower3.h:189
nanopower3_write_data
err_t nanopower3_write_data(nanopower3_t *ctx, uint8_t cmd, uint8_t data_in)
Nano Power 3 command writing function.
nanopower3_set_wiper_pos
err_t nanopower3_set_wiper_pos(nanopower3_t *ctx, uint8_t wiper_pos)
Nano Power 3 set wiper position function.
nanopower3_cfg_t
Nano Power 3 Click configuration object.
Definition: nanopower3.h:183
nanopower3_cfg_t::scl
pin_name_t scl
Definition: nanopower3.h:184
nanopower3_t
Nano Power 3 Click context object.
Definition: nanopower3.h:162
nanopower3_set_ctr_pin
void nanopower3_set_ctr_pin(nanopower3_t *ctx, uint8_t pin_state)
Nano Power 3 set CTRL pin state function.
NANOPOWER3_ERROR
@ NANOPOWER3_ERROR
Definition: nanopower3.h:203
nanopower3_t::an
digital_in_t an
Definition: nanopower3.h:167
nanopower3_t::pg
digital_in_t pg
Definition: nanopower3.h:168
nanopower3_default_cfg
err_t nanopower3_default_cfg(nanopower3_t *ctx)
Nano Power 3 default configuration function.
nanopower3_t::i2c
i2c_master_t i2c
Definition: nanopower3.h:171
nanopower3_return_value_t
nanopower3_return_value_t
Nano Power 3 Click return value data.
Definition: nanopower3.h:201
nanopower3_generic_write
err_t nanopower3_generic_write(nanopower3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Nano Power 3 I2C writing function.
nanopower3_init
err_t nanopower3_init(nanopower3_t *ctx, nanopower3_cfg_t *cfg)
Nano Power 3 initialization function.
nanopower3_get_pg_pin_state
uint8_t nanopower3_get_pg_pin_state(nanopower3_t *ctx)
Nano Power 3 get PG pin state function.
nanopower3_cfg_t::sda
pin_name_t sda
Definition: nanopower3.h:185
nanopower3_cfg_t::ctr
pin_name_t ctr
Definition: nanopower3.h:188
NANOPOWER3_OK
@ NANOPOWER3_OK
Definition: nanopower3.h:202
nanopower3_cfg_setup
void nanopower3_cfg_setup(nanopower3_cfg_t *cfg)
Nano Power 3 configuration object setup function.
nanopower3_t::ctr
digital_out_t ctr
Definition: nanopower3.h:164
nanopower3_t::slave_address
uint8_t slave_address
Definition: nanopower3.h:174
nanopower3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: nanopower3.h:191
nanopower3_generic_read
err_t nanopower3_generic_read(nanopower3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Nano Power 3 I2C reading function.
nanopower3_set_resistance
err_t nanopower3_set_resistance(nanopower3_t *ctx, uint32_t resistance)
Nano Power 3 set resistance function.