Loading...
Searching...
No Matches
mcp47xx.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Gunar Schorcht
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
105
106#ifdef __cplusplus
107extern "C"
108{
109#endif
110
111#include <stdbool.h>
112#include <stdint.h>
113
114#include "kernel_defines.h"
115#include "periph/dac.h"
116#include "periph/gpio.h"
117#include "periph/i2c.h"
118
127#define MCP47XX_BASE_ADDR (0x60)
131
136#define MCP4706_CHN_NUM (1)
137#define MCP4716_CHN_NUM (1)
138#define MCP4725_CHN_NUM (1)
139#define MCP4726_CHN_NUM (1)
140#define MCP4728_CHN_NUM (4)
141#define MCP47XX_CHN_NUM_MAX (4)
143
151
165
175
187
205
220
230
231#if IS_USED(MODULE_SAUL) || DOXYGEN
235typedef struct {
236 const char *name;
237 unsigned int dev;
238 uint8_t channel;
239 uint16_t initial;
241#endif
242
255int mcp47xx_init(mcp47xx_t *dev, const mcp47xx_params_t *params);
256
270int mcp47xx_dac_init(mcp47xx_t *dev, uint8_t chn);
271
284void mcp47xx_dac_set(mcp47xx_t *dev, uint8_t chn, uint16_t value);
285
296void mcp47xx_dac_get(mcp47xx_t *dev, uint8_t chn, uint16_t *value);
297
306void mcp47xx_dac_poweron(mcp47xx_t *dev, uint8_t chn);
307
321void mcp47xx_dac_poweroff(mcp47xx_t *dev, uint8_t chn);
322
333
334#ifdef __cplusplus
335}
336#endif
337
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:146
mcp47xx_gain_t
MCP47xx gain configuration type.
Definition mcp47xx.h:171
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:181
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:141
mcp47xx_pd_mode_t
MCP47xx Power-down mode selection type.
Definition mcp47xx.h:197
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:158
@ MCP47XX_ERROR_NOT_AVAIL
device not available
Definition mcp47xx.h:149
@ MCP47XX_ERROR_I2C
I2C communication error.
Definition mcp47xx.h:148
@ MCP47XX_OK
success
Definition mcp47xx.h:147
@ MCP47XX_GAIN_2X
Gain is 2.0, not supported by MCP4725.
Definition mcp47xx.h:173
@ MCP47XX_GAIN_1X
Gain is 1.0, supported by all MCP47xx variants.
Definition mcp47xx.h:172
@ MCP47XX_VREF_PIN
V_REF = VREF pin not buffered, MCP47x6 only.
Definition mcp47xx.h:184
@ MCP47XX_VREF_BUF
V_REF = VREF pin buffered, MCP47x6 only.
Definition mcp47xx.h:185
@ MCP47XX_VREF_VDD
V_REF = V_DD, supported by all MCP47xx.
Definition mcp47xx.h:182
@ MCP47XX_VREF_INT
V_REF = internal (2.048 V), MCP4728 only.
Definition mcp47xx.h:183
@ MCP47XX_NORMAL
Normal mode.
Definition mcp47xx.h:198
@ MCP47XX_PD_MEDIUM
Power down, medium resistor, 125 kOhm for MCP47x6, 100 kOhm otherwise.
Definition mcp47xx.h:200
@ MCP47XX_PD_LARGE
Power down, large resistor, 640 kOhm for MCP47x6, 125 kOhm otherwise.
Definition mcp47xx.h:202
@ MCP47XX_PD_SMALL
Power down, small resistor 1 kOhm.
Definition mcp47xx.h:199
@ MCP4728
4 channel 12-bit DAC
Definition mcp47xx.h:163
@ MCP4726
1 channel 12-bit DAC
Definition mcp47xx.h:162
@ MCP4706
1 channel 8-bit DAC
Definition mcp47xx.h:159
@ MCP4725
1 channel 12-bit DAC
Definition mcp47xx.h:161
@ MCP4716
1 channel 10-bit DAC
Definition mcp47xx.h:160
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
MCP47xx device configuration parameters.
Definition mcp47xx.h:209
uint16_t addr
I2C slave address MCP47XX_BASE_ADDR + [0...7].
Definition mcp47xx.h:212
mcp47xx_vref_t vref
Voltage reference selection.
Definition mcp47xx.h:216
i2c_t dev
I2C device.
Definition mcp47xx.h:211
mcp47xx_gain_t gain
Gain selection.
Definition mcp47xx.h:215
mcp47xx_variant_t variant
used variant of MCP47xx
Definition mcp47xx.h:214
mcp47xx_pd_mode_t pd_mode
Power-down mode selection.
Definition mcp47xx.h:217
MCP47xx configuration structure for mapping DAC channels to SAUL.
Definition mcp47xx.h:235
unsigned int dev
index of the MCP47xx device
Definition mcp47xx.h:237
uint16_t initial
initial value
Definition mcp47xx.h:239
const char * name
name of the MCP47xx device
Definition mcp47xx.h:236
uint8_t channel
channel of the MCP47xx device
Definition mcp47xx.h:238
MCP47xx device data structure type.
Definition mcp47xx.h:224
mcp47xx_params_t params
device configuration parameters
Definition mcp47xx.h:225
uint16_t values[MCP47XX_CHN_NUM_MAX]
contains the last values set for persistence when device is powered off
Definition mcp47xx.h:226