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
9#pragma once
10
108
109#ifdef __cplusplus
110extern "C"
111{
112#endif
113
114#include <stdbool.h>
115#include <stdint.h>
116
117#include "kernel_defines.h"
118#include "periph/dac.h"
119#include "periph/gpio.h"
120#include "periph/i2c.h"
121
130#define MCP47XX_BASE_ADDR (0x60)
134
139#define MCP4706_CHN_NUM (1)
140#define MCP4716_CHN_NUM (1)
141#define MCP4725_CHN_NUM (1)
142#define MCP4726_CHN_NUM (1)
143#define MCP4728_CHN_NUM (4)
144#define MCP47XX_CHN_NUM_MAX (4)
146
154
168
178
190
208
223
233
234#if IS_USED(MODULE_SAUL) || DOXYGEN
238typedef struct {
239 const char *name;
240 unsigned int dev;
241 uint8_t channel;
242 uint16_t initial;
244#endif
245
258int mcp47xx_init(mcp47xx_t *dev, const mcp47xx_params_t *params);
259
273int mcp47xx_dac_init(mcp47xx_t *dev, uint8_t chn);
274
287void mcp47xx_dac_set(mcp47xx_t *dev, uint8_t chn, uint16_t value);
288
299void mcp47xx_dac_get(mcp47xx_t *dev, uint8_t chn, uint16_t *value);
300
309void mcp47xx_dac_poweron(mcp47xx_t *dev, uint8_t chn);
310
324void mcp47xx_dac_poweroff(mcp47xx_t *dev, uint8_t chn);
325
336
337#ifdef __cplusplus
338}
339#endif
340
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:149
mcp47xx_gain_t
MCP47xx gain configuration type.
Definition mcp47xx.h:174
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:184
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:144
mcp47xx_pd_mode_t
MCP47xx Power-down mode selection type.
Definition mcp47xx.h:200
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:161
@ MCP47XX_ERROR_NOT_AVAIL
device not available
Definition mcp47xx.h:152
@ MCP47XX_ERROR_I2C
I2C communication error.
Definition mcp47xx.h:151
@ MCP47XX_OK
success
Definition mcp47xx.h:150
@ MCP47XX_GAIN_2X
Gain is 2.0, not supported by MCP4725.
Definition mcp47xx.h:176
@ MCP47XX_GAIN_1X
Gain is 1.0, supported by all MCP47xx variants.
Definition mcp47xx.h:175
@ MCP47XX_VREF_PIN
V_REF = VREF pin not buffered, MCP47x6 only.
Definition mcp47xx.h:187
@ MCP47XX_VREF_BUF
V_REF = VREF pin buffered, MCP47x6 only.
Definition mcp47xx.h:188
@ MCP47XX_VREF_VDD
V_REF = V_DD, supported by all MCP47xx.
Definition mcp47xx.h:185
@ MCP47XX_VREF_INT
V_REF = internal (2.048 V), MCP4728 only.
Definition mcp47xx.h:186
@ MCP47XX_NORMAL
Normal mode.
Definition mcp47xx.h:201
@ MCP47XX_PD_MEDIUM
Power down, medium resistor, 125 kOhm for MCP47x6, 100 kOhm otherwise.
Definition mcp47xx.h:203
@ MCP47XX_PD_LARGE
Power down, large resistor, 640 kOhm for MCP47x6, 125 kOhm otherwise.
Definition mcp47xx.h:205
@ MCP47XX_PD_SMALL
Power down, small resistor 1 kOhm.
Definition mcp47xx.h:202
@ MCP4728
4 channel 12-bit DAC
Definition mcp47xx.h:166
@ MCP4726
1 channel 12-bit DAC
Definition mcp47xx.h:165
@ MCP4706
1 channel 8-bit DAC
Definition mcp47xx.h:162
@ MCP4725
1 channel 12-bit DAC
Definition mcp47xx.h:164
@ MCP4716
1 channel 10-bit DAC
Definition mcp47xx.h:163
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:144
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
MCP47xx device configuration parameters.
Definition mcp47xx.h:212
uint16_t addr
I2C slave address MCP47XX_BASE_ADDR + [0...7].
Definition mcp47xx.h:215
mcp47xx_vref_t vref
Voltage reference selection.
Definition mcp47xx.h:219
i2c_t dev
I2C device.
Definition mcp47xx.h:214
mcp47xx_gain_t gain
Gain selection.
Definition mcp47xx.h:218
mcp47xx_variant_t variant
used variant of MCP47xx
Definition mcp47xx.h:217
mcp47xx_pd_mode_t pd_mode
Power-down mode selection.
Definition mcp47xx.h:220
MCP47xx configuration structure for mapping DAC channels to SAUL.
Definition mcp47xx.h:238
unsigned int dev
index of the MCP47xx device
Definition mcp47xx.h:240
uint16_t initial
initial value
Definition mcp47xx.h:242
const char * name
name of the MCP47xx device
Definition mcp47xx.h:239
uint8_t channel
channel of the MCP47xx device
Definition mcp47xx.h:241
MCP47xx device data structure type.
Definition mcp47xx.h:227
mcp47xx_params_t params
device configuration parameters
Definition mcp47xx.h:228
uint16_t values[MCP47XX_CHN_NUM_MAX]
contains the last values set for persistence when device is powered off
Definition mcp47xx.h:229