Loading...
Searching...
No Matches
mcp47xx.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Gunar Schorcht
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
107#ifndef MCP47XX_H
108#define MCP47XX_H
109
110#ifdef __cplusplus
111extern "C"
112{
113#endif
114
115#include <stdbool.h>
116#include <stdint.h>
117
118#include "kernel_defines.h"
119#include "periph/dac.h"
120#include "periph/gpio.h"
121#include "periph/i2c.h"
122
131#define MCP47XX_BASE_ADDR (0x60)
140#define MCP4706_CHN_NUM (1)
141#define MCP4716_CHN_NUM (1)
142#define MCP4725_CHN_NUM (1)
143#define MCP4726_CHN_NUM (1)
144#define MCP4728_CHN_NUM (4)
145#define MCP47XX_CHN_NUM_MAX (4)
155
169
179
191
209
224
228typedef struct {
230 uint16_t values[MCP47XX_CHN_NUM_MAX];
233} mcp47xx_t;
234
235#if IS_USED(MODULE_SAUL) || DOXYGEN
239typedef struct {
240 const char *name;
241 unsigned int dev;
242 uint8_t channel;
243 uint16_t initial;
245#endif
246
259int mcp47xx_init(mcp47xx_t *dev, const mcp47xx_params_t *params);
260
274int mcp47xx_dac_init(mcp47xx_t *dev, uint8_t chn);
275
290void mcp47xx_dac_set(mcp47xx_t *dev, uint8_t chn, uint16_t value);
291
304void mcp47xx_dac_get(mcp47xx_t *dev, uint8_t chn, uint16_t *value);
305
315void mcp47xx_dac_poweron(mcp47xx_t *dev, uint8_t chn);
316
331void mcp47xx_dac_poweroff(mcp47xx_t *dev, uint8_t chn);
332
343
344#ifdef __cplusplus
345}
346#endif
347
348#endif /* MCP47XX_H */
DAC peripheral driver interface definition.
Low-level GPIO peripheral driver interface definitions.
void mcp47xx_dac_poweroff(mcp47xx_t *dev, uint8_t chn)
Disables the MCP47xx DAC device.
mcp47xx_error_codes_t
MCP47xx driver error codes.
Definition mcp47xx.h:150
mcp47xx_gain_t
MCP47xx gain configuration type.
Definition mcp47xx.h:175
void mcp47xx_dac_get(mcp47xx_t *dev, uint8_t chn, uint16_t *value)
Get the current value of a MCP47xx DAC channel.
int mcp47xx_dac_init(mcp47xx_t *dev, uint8_t chn)
Initialize a MCP47xx DAC channel.
void mcp47xx_dac_poweron(mcp47xx_t *dev, uint8_t chn)
Enables the MCP47xx DAC device.
mcp47xx_vref_t
MCP47xx V_REF configuration type.
Definition mcp47xx.h:185
void mcp47xx_dac_set(mcp47xx_t *dev, uint8_t chn, uint16_t value)
Write a value to a MCP47xx DAC channel.
int mcp47xx_init(mcp47xx_t *dev, const mcp47xx_params_t *params)
Initialize the MCP47xx DAC.
#define MCP47XX_CHN_NUM_MAX
maximum number of channels
Definition mcp47xx.h:145
mcp47xx_pd_mode_t
MCP47xx Power-down mode selection type.
Definition mcp47xx.h:201
uint8_t mcp47xx_dac_channels(mcp47xx_t *dev)
Returns the number of channels of MCP47xx DAC device.
mcp47xx_variant_t
Supported MCP47xx variants.
Definition mcp47xx.h:162
@ MCP47XX_ERROR_NOT_AVAIL
device not available
Definition mcp47xx.h:153
@ MCP47XX_ERROR_I2C
I2C communication error.
Definition mcp47xx.h:152
@ MCP47XX_OK
success
Definition mcp47xx.h:151
@ MCP47XX_GAIN_2X
Gain is 2.0, not supported by MCP4725.
Definition mcp47xx.h:177
@ MCP47XX_GAIN_1X
Gain is 1.0, supported by all MCP47xx variants.
Definition mcp47xx.h:176
@ MCP47XX_VREF_PIN
V_REF = VREF pin not buffered, MCP47x6 only.
Definition mcp47xx.h:188
@ MCP47XX_VREF_BUF
V_REF = VREF pin buffered, MCP47x6 only.
Definition mcp47xx.h:189
@ MCP47XX_VREF_VDD
V_REF = V_DD, supported by all MCP47xx.
Definition mcp47xx.h:186
@ MCP47XX_VREF_INT
V_REF = internal (2.048 V), MCP4728 only
Definition mcp47xx.h:187
@ MCP47XX_NORMAL
Normal mode.
Definition mcp47xx.h:202
@ MCP47XX_PD_MEDIUM
Power down, medium resistor, 125 kOhm for MCP47x6, 100 kOhm otherwise.
Definition mcp47xx.h:204
@ MCP47XX_PD_LARGE
Power down, large resistor, 640 kOhm for MCP47x6, 125 kOhm otherwise.
Definition mcp47xx.h:206
@ MCP47XX_PD_SMALL
Power down, small resistor 1 kOhm.
Definition mcp47xx.h:203
@ MCP4728
4 channel 12-bit DAC
Definition mcp47xx.h:167
@ MCP4726
1 channel 12-bit DAC
Definition mcp47xx.h:166
@ MCP4706
1 channel 8-bit DAC
Definition mcp47xx.h:163
@ MCP4725
1 channel 12-bit DAC
Definition mcp47xx.h:165
@ MCP4716
1 channel 10-bit DAC
Definition mcp47xx.h:164
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
MCP47xx device configuration parameters.
Definition mcp47xx.h:213
uint16_t addr
I2C slave address MCP47XX_BASE_ADDR + [0...7].
Definition mcp47xx.h:216
mcp47xx_vref_t vref
Voltage reference selection.
Definition mcp47xx.h:220
i2c_t dev
I2C device.
Definition mcp47xx.h:215
mcp47xx_gain_t gain
Gain selection.
Definition mcp47xx.h:219
mcp47xx_variant_t variant
used variant of MCP47xx
Definition mcp47xx.h:218
mcp47xx_pd_mode_t pd_mode
Power-down mode selection.
Definition mcp47xx.h:221
MCP47xx configuration structure for mapping DAC channels to SAUL.
Definition mcp47xx.h:239
unsigned int dev
index of the MCP47xx device
Definition mcp47xx.h:241
uint16_t initial
initial value
Definition mcp47xx.h:243
const char * name
name of the MCP47xx device
Definition mcp47xx.h:240
uint8_t channel
channel of the MCP47xx device
Definition mcp47xx.h:242
MCP47xx device data structure type.
Definition mcp47xx.h:228
mcp47xx_params_t params
device configuration parameters
Definition mcp47xx.h:229