-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sensorium/Mozzi
- Loading branch information
Showing
5 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Parts of this file are drawn from Arduino's source code for analogRead() (https://github.com/arduino/ArduinoCore-renesas/blob/main/cores/arduino/analog.cpp) and part from Renesas' documentation (https://renesas.github.io/fsp/group___a_d_c.html), among other things. | ||
It contains functions to interact with the ADC in order to implement async ADC reads, aka mozziAnalogRead(). | ||
*/ | ||
|
||
#include <analog.h> | ||
#include <analog.cpp> | ||
#include <IRQManager.h> | ||
|
||
|
||
|
||
|
||
//////////////////// ADC ////////////// | ||
|
||
void startScan(int pin) | ||
{ | ||
int32_t adc_idx = digitalPinToAnalogPin(pin); | ||
ADC_Container *_adc = get_ADC_container_ptr(adc_idx, cfg_adc); | ||
_adc->cfg.mode = ADC_MODE_SINGLE_SCAN; | ||
pinPeripheral(digitalPinToBspPin(adc_idx), (uint32_t)IOPORT_CFG_ANALOG_ENABLE); | ||
_adc->channel_cfg.scan_mask |= (1 << GET_CHANNEL(cfg_adc)); | ||
R_ADC_Open(&(_adc->ctrl), &(_adc->cfg)); | ||
R_ADC_CallbackSet(&(_adc->ctrl), adc_callback, p_context, p_callback_memory); | ||
R_ADC_ScanCfg(&(_adc->ctrl), &(_adc->channel_cfg)); | ||
R_ADC_ScanStart(&(_adc->ctrl)); | ||
} | ||
|
||
uint16_t readADC(int pin) | ||
{ | ||
uint16_t result; | ||
int32_t adc_idx = digitalPinToAnalogPin(pin); | ||
ADC_Container *_adc = get_ADC_container_ptr(adc_idx, cfg_adc); | ||
R_ADC_Read(&(_adc->ctrl), (adc_channel_t)GET_CHANNEL(cfg_adc), &result); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters