rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Functions
mcp3208.h File Reference

Data Structures

struct  McpAdcState
 MCP3208 ADC chip driver structure. More...
 

Functions

void init_adc_mcp3208 (McpAdcState *state, SPIDriver *driver)
 
void requestAdcValue (McpAdcState *state, int channel)
 
void requestAdcValueI (McpAdcState *state, int channel)
 
void adc_in_out (McpAdcState *state)
 
int getMcp3208adc (int channel)
 

Function Documentation

◆ adc_in_out()

void adc_in_out ( McpAdcState state)

Definition at line 98 of file mcp3208.cpp.

98 {
99
100// chThdSleepMilliseconds(10);
101
102 int result = state->results[0];
103
104// int v = result;
105 unsigned r = 0;
106//
107// while (v >>= 1)
108// r++;
109//
110// unsigned int f;
111// if (r < 12) {
112// f = -1;
113// } else {
114// f = result >> (r - 12);
115// f = f & 4095;
116// }
117
118 int errRatio = 1000 * adcErrorCounter / adcEventCounter;
119
120 print("c/e %7d/%7d/%4d result %5d r=%d ", adcEventCounter, adcErrorCounter, errRatio, result, r);
121
122 unsigned int f0 = getValue(state, 0);
123 print("ch0=%d adj %d ", f0, f0 * 5000 / 4096);
124 unsigned int f1 = getValue(state, 1);
125 print("ch1=%d adj %d\r\n", f1, f1 * 5000 / 4096);
126}
static int adcEventCounter
Definition mcp3208.cpp:20
static int adcErrorCounter
Definition mcp3208.cpp:21
static int getValue(McpAdcState *state, int channel)
Definition mcp3208.cpp:23
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1871, 1.0, -1.0, -1.0, "")
Here is the call graph for this function:

◆ getMcp3208adc()

int getMcp3208adc ( int  channel)

Definition at line 27 of file mcp3208.cpp.

27 {
28 return getValue(hack, channel);
29}
uint16_t channel
Definition adc_inputs.h:104
McpAdcState * hack
Definition mcp3208.cpp:18
Here is the call graph for this function:

◆ init_adc_mcp3208()

void init_adc_mcp3208 ( McpAdcState state,
SPIDriver *  driver 
)

Definition at line 128 of file mcp3208.cpp.

128 {
129 state->driver = driver;
130 state->tx_buff[2] = 0;
131
132 hack = state;
133
134 todo: convert to new API, todo: array of CS
135 mySetPadMod("ext adc chip select", MCP3208_CS_PORT, MCP3208_CS_PIN, PAL_STM32_MODE_OUTPUT);
136
137
138 spiStart(driver, &spicfg);
139}
static const SPIConfig spicfg
Definition mcp3208.cpp:64
Here is the call graph for this function:

◆ requestAdcValue()

void requestAdcValue ( McpAdcState state,
int  channel 
)

Definition at line 82 of file mcp3208.cpp.

82 {
84
85 spiSelect(state->driver);
86 spiStartExchange(state->driver, 3, state->tx_buff, state->rx_buff);
87 // SPI unselect is in the callback
88}
static void createRequest(McpAdcState *state, int channel)
Definition mcp3208.cpp:73
Here is the call graph for this function:

◆ requestAdcValueI()

void requestAdcValueI ( McpAdcState state,
int  channel 
)

Definition at line 90 of file mcp3208.cpp.

90 {
92
93 spiSelectI(state->driver);
94 spiStartExchangeI(state->driver, 3, state->tx_buff, state->rx_buff);
95 // SPI unselect is in the callback
96}

Referenced by spiCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.