rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
poten.cpp File Reference

Detailed Description

MCP42010 digital potentiometer driver.

Date
Mar 16, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file poten.cpp.

Functions

void initPotentiometer (Mcp42010Driver *driver, SPIDriver *spi, brain_pin_e csPin)
 
static int getPotStep (int resistanceWA)
 
static void sendToPot (Mcp42010Driver *driver, int channel, int value)
 
void setPotResistance (Mcp42010Driver *driver, int channel, int resistance)
 
static void setPotResistanceCommand (int index, int value)
 
static void setPotValue1 (int value)
 
void initPotentiometers ()
 

Variables

static Mcp42010Driver potConfig [DIGIPOT_COUNT]
 

Function Documentation

◆ getPotStep()

static int getPotStep ( int  resistanceWA)
static

Definition at line 58 of file poten.cpp.

58 {
59 return 256 - (int) ((resistanceWA - 52) * 256 / 10000);
60}

Referenced by setPotResistance().

Here is the caller graph for this function:

◆ initPotentiometer()

void initPotentiometer ( Mcp42010Driver driver,
SPIDriver *  spi,
brain_pin_e  csPin 
)

Definition at line 52 of file poten.cpp.

52 {
53 driver->spiConfig.cr1 = SPI_POT_CONFIG;
54 driver->spi = spi;
55 initSpiCs(&driver->spiConfig, csPin);
56}
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin)
Definition at32_spi.cpp:241
SPIConfig spiConfig
Definition poten.h:19
SPIDriver * spi
Definition poten.h:18

Referenced by initPotentiometers().

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

◆ initPotentiometers()

void initPotentiometers ( )

Definition at line 90 of file poten.cpp.

90 {
91#if EFI_POTENTIOMETER
93 efiPrintf("digiPot spi disabled");
94 return;
95 }
96 // todo: we have centralized SPI management see other usages of 'turnOnSpi'
97 //turnOnSpi(engineConfiguration->digitalPotentiometerSpiDevice);
98
99 for (int i = 0; i < DIGIPOT_COUNT; i++) {
101 if (!isBrainPinValid(csPin)) {
102 continue;
103 }
104
106 if (driver == NULL) {
107 // error already reported
108 return;
109 }
110
111 initPotentiometer(&potConfig[i], driver, csPin);
112 }
113
115
117
118 setPotResistance(&potConfig[0], 0, 3000);
119 setPotResistance(&potConfig[0], 1, 7000);
120#endif
121}
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
static constexpr engine_configuration_s * engineConfiguration
SPIDriver * getSpiDevice(spi_device_e spiDevice)
Definition hardware.cpp:149
bool isBrainPinValid(brain_pin_e brainPin)
void initPotentiometer(Mcp42010Driver *driver, SPIDriver *spi, brain_pin_e csPin)
Definition poten.cpp:52
void setPotResistance(Mcp42010Driver *driver, int channel, int resistance)
Definition poten.cpp:73
static void setPotResistanceCommand(int index, int value)
Definition poten.cpp:80
static Mcp42010Driver potConfig[DIGIPOT_COUNT]
Definition poten.cpp:50
static void setPotValue1(int value)
Definition poten.cpp:84

Referenced by initEngineEmulator().

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

◆ sendToPot()

static void sendToPot ( Mcp42010Driver driver,
int  channel,
int  value 
)
static

Definition at line 62 of file poten.cpp.

62 {
63 lockSpi(SPI_NONE);
64 spiStart(driver->spi, &driver->spiConfig);
65 spiSelect(driver->spi);
66 int word = (17 + channel) * 256 + value;
67 spiSend(driver->spi, 1, &word);
68 spiUnselect(driver->spi);
69 spiStop(driver->spi);
70 unlockSpi(SPI_NONE);
71}
uint16_t channel
Definition adc_inputs.h:104
void unlockSpi(spi_device_e device)
Definition hardware.cpp:195
void lockSpi(spi_device_e device)
Definition hardware.cpp:190

Referenced by setPotResistance(), and setPotValue1().

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

◆ setPotResistance()

void setPotResistance ( Mcp42010Driver driver,
int  channel,
int  resistance 
)

Definition at line 73 of file poten.cpp.

73 {
74 int value = getPotStep(resistance);
75
76 efiPrintf("Sending to potentiometer%d: %d for R=%d", channel, value, resistance);
77 sendToPot(driver, channel, value);
78}
static int getPotStep(int resistanceWA)
Definition poten.cpp:58
static void sendToPot(Mcp42010Driver *driver, int channel, int value)
Definition poten.cpp:62

Referenced by initPotentiometers(), and setPotResistanceCommand().

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

◆ setPotResistanceCommand()

static void setPotResistanceCommand ( int  index,
int  value 
)
static

Definition at line 80 of file poten.cpp.

80 {
81 setPotResistance(&potConfig[index / 2], index % 2, value);
82}

Referenced by initPotentiometers().

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

◆ setPotValue1()

static void setPotValue1 ( int  value)
static

Definition at line 84 of file poten.cpp.

84 {
85 sendToPot(&potConfig[0], 1, value);
86}

Referenced by initPotentiometers().

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

Variable Documentation

◆ potConfig

Mcp42010Driver potConfig[DIGIPOT_COUNT]
static

Definition at line 50 of file poten.cpp.

Referenced by initPotentiometers(), setPotResistanceCommand(), and setPotValue1().

Go to the source code of this file.