39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
74#define C420MAT2_REG_XFER 0x01
75#define C420MAT2_REG_NOP 0x02
76#define C420MAT2_REG_WR_MODE 0x03
77#define C420MAT2_REG_DACCODE 0x04
78#define C420MAT2_REG_ERR_CONFIG 0x05
79#define C420MAT2_REG_ERR_LOW 0x06
80#define C420MAT2_REG_ERR_HIGH 0x07
81#define C420MAT2_REG_RESET 0x08
82#define C420MAT2_REG_STATUS 0x09
100#define C420MAT2_CMD_XFER 0x00FF
101#define C420MAT2_CMD_NOP 0x0000
102#define C420MAT2_CMD_WR_MODE_DISABLE 0x0000
103#define C420MAT2_CMD_WR_MODE_ENABLE 0x0001
104#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_50ms 0x0000
105#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_100ms 0x0100
106#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_150ms 0x0200
107#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_200ms 0x0300
108#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_250ms 0x0400
109#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_300ms 0x0500
110#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_350ms 0x0600
111#define C420MAT2_CMD_RETRY_TIMEL_RETRY_TIME_400ms 0x0700
112#define C420MAT2_CMD_DIS_RETRY_LOOP_DISABLE 0x0000
113#define C420MAT2_CMD_DIS_RETRY_LOOP_ENABLE 0x0080
114#define C420MAT2_CMD_MASK_LOOP_ERR_DISABLE 0x0000
115#define C420MAT2_CMD_MASK_LOOP_ERR_ENABLE 0x0040
116#define C420MAT2_CMD_DIS_LOOP_ERR_ERRB_DISABLE 0x0000
117#define C420MAT2_CMD_DIS_LOOP_ERR_ERRB_ENABLE 0x0020
118#define C420MAT2_CMD_MASK_SPI_ERR_DISABLE 0x0000
119#define C420MAT2_CMD_MASK_SPI_ERR_ENABLE 0x0010
120#define C420MAT2_CMD_SPI_TIMEOUT_50ms 0x0000
121#define C420MAT2_CMD_SPI_TIMEOUT_100ms 0x0002
122#define C420MAT2_CMD_SPI_TIMEOUT_150ms 0x0004
123#define C420MAT2_CMD_SPI_TIMEOUT_200ms 0x0006
124#define C420MAT2_CMD_SPI_TIMEOUT_250ms 0x0008
125#define C420MAT2_CMD_SPI_TIMEOUT_300ms 0x000A
126#define C420MAT2_CMD_SPI_TIMEOUT_350ms 0x000C
127#define C420MAT2_CMD_SPI_TIMEOUT_400ms 0x000E
128#define C420MAT2_CMD_MASK_SPI_TOUT_DISABLE 0x0000
129#define C420MAT2_CMD_MASK_SPI_TOUT_ENABLE 0x0001
130#define C420MAT2_CMD_RESET 0xC33C
136#define C420MAT2_STATUS_DAC_RES_BIT_MASK 0x00E0
137#define C420MAT2_STATUS_ERRLVL_PIN_BIT_MASK 0x0010
138#define C420MAT2_STATUS_FERR_STS_BIT_MASK 0x0008
139#define C420MAT2_STATUSSPI_TIMEOUT_ERR_BIT_MASK 0x0004
140#define C420MAT2_STATUS_LOOP_STS_BIT_MASK 0x0002
141#define C420MAT2_STATUS_CURR_LOOP_STS_BIT_MASK 0x0001
152#define C420MAT2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
153#define C420MAT2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
171#define C420MAT2_MAP_MIKROBUS( cfg, mikrobus ) \
172 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
173 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
174 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
175 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
176 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
177 cfg.err = MIKROBUS( mikrobus, MIKROBUS_INT )
c420mat2_return_value_t
4-20mA T 2 Click return value data.
Definition c420mat2.h:229
@ C420MAT2_OK
Definition c420mat2.h:230
@ C420MAT2_ERROR
Definition c420mat2.h:231
c420mat2_status_value_t
4-20mA T 2 Click error status value data.
Definition c420mat2.h:254
@ C420MAT2_STATUS_ERROR
Definition c420mat2.h:256
@ C420MAT2_STATUS_OK
Definition c420mat2.h:255
err_t c420mat2_protected_write(c420mat2_t *ctx, uint8_t reg, uint16_t data_in)
4-20mA T 2 protected data writing function.
err_t c420mat2_init(c420mat2_t *ctx, c420mat2_cfg_t *cfg)
4-20mA T 2 initialization function.
err_t c420mat2_set_upper_limit(c420mat2_t *ctx, float upper_limit_ma)
4-20mA T 2 set upper limit function.
err_t c420mat2_set_output_current(c420mat2_t *ctx, float current_ma)
4-20mA T 2 set output current function.
err_t c420mat2_get_status(c420mat2_t *ctx, c420mat2_status_t *status)
4-20mA T 2 set status function.
uint8_t c420mat2_get_err_pin(c420mat2_t *ctx)
4-20mA T 2 get error flag pin state function.
err_t c420mat2_default_cfg(c420mat2_t *ctx)
4-20mA T 2 default configuration function.
err_t c420mat2_sw_reset(c420mat2_t *ctx)
4-20mA T 2 soft reset function.
err_t c420mat2_write_data(c420mat2_t *ctx, uint8_t reg, uint16_t data_in)
4-20mA T 2 data writing function.
err_t c420mat2_read_data(c420mat2_t *ctx, uint8_t cmd, uint16_t *data_out)
4-20mA T 2 data reading function.
err_t c420mat2_set_lower_limit(c420mat2_t *ctx, float lower_limit_ma)
4-20mA T 2 set lower limit function.
void c420mat2_cfg_setup(c420mat2_cfg_t *cfg)
4-20mA T 2 configuration object setup function.
err_t c420mat2_set_dac_data(c420mat2_t *ctx, uint16_t dac_output_code)
4-20mA T 2 set DAC data function.
This file contains SPI specific macros, functions, etc.
4-20mA T 2 Click configuration object.
Definition c420mat2.h:206
spi_master_chip_select_polarity_t cs_polarity
Definition c420mat2.h:220
pin_name_t sck
Definition c420mat2.h:210
pin_name_t err
Definition c420mat2.h:215
spi_master_mode_t spi_mode
Definition c420mat2.h:219
pin_name_t mosi
Definition c420mat2.h:209
uint32_t spi_speed
Definition c420mat2.h:218
pin_name_t miso
Definition c420mat2.h:208
pin_name_t rst
Definition c420mat2.h:214
pin_name_t cs
Definition c420mat2.h:211
4-20mA T 2 Click status object.
Definition c420mat2.h:240
uint8_t loop_sts
Definition c420mat2.h:244
uint8_t spi_timeout_err
Definition c420mat2.h:243
uint8_t ferr_sts
Definition c420mat2.h:242
uint8_t curr_loop_sts
Definition c420mat2.h:245
uint8_t errlvl_pin
Definition c420mat2.h:241
4-20mA T 2 Click context object.
Definition c420mat2.h:187
spi_master_t spi
Definition c420mat2.h:195
digital_out_t rst
Definition c420mat2.h:189
digital_in_t err
Definition c420mat2.h:192
pin_name_t chip_select
Definition c420mat2.h:197