Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sensorium/Mozzi
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcombriat committed Oct 10, 2023
2 parents e782561 + a0c7336 commit 39fb92c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
with:
project-type: library
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compile_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Compile examples
uses: arduino/compile-sketches@v1
Expand Down
40 changes: 20 additions & 20 deletions MozziGuts_impl_RENESAS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,45 @@

////// BEGIN analog input code ////////

//#define MOZZI_FAST_ANALOG_IMPLEMENTED

#define getADCReading() 0
#define channelNumToIndex(channel) channel-14 // A0=14
void const *const p_context = 0; // unused but needed for the ADC call
adc_callback_args_t *const p_callback_memory = NULL; // idem
uint16_t cfg_adc = 0; // put at 0 for starters but modified by the ADC_container
uint8_t r4_pin; // to store it between calls

void adc_callback(adc_callback_args_t *p_args) {
advanceADCStep();
}

#include "MozziGuts_impl_RENESAS_ADC.hpp"

#define MOZZI_FAST_ANALOG_IMPLEMENTED

#define getADCReading() readADC(r4_pin)

#define channelNumToIndex(channel) channel
uint8_t adcPinToChannelNum(uint8_t pin) {
return pin;
}

/** NOTE: Code needed to trigger a conversion on a new channel */
void adcStartConversion(uint8_t channel) {
#warning Fast analog read not implemented on this platform
r4_pin = channel; // remember for startSecondADCReadOnCurrentChannel()
startScan(r4_pin);
}

/** NOTE: Code needed to trigger a subsequent conversion on the latest channel. If your platform has no special code for it, you should store the channel from
* adcStartConversion(), and simply call adcStartConversion(previous_channel), here. */
void startSecondADCReadOnCurrentChannel() {
#warning Fast analog read not implemented on this platform
startScan(r4_pin);
}

/** NOTE: Code needed to set up faster than usual analog reads, e.g. specifying the number of CPU cycles that the ADC waits for the result to stabilize.
* This particular function is not super important, so may be ok to leave empty, at least, if the ADC is fast enough by default. */
void setupFastAnalogRead(int8_t speed) {
#warning Fast analog read not implemented on this platform
//#warning Fast analog read not implemented on this platform
}

/** NOTE: Code needed to initialize the ADC for asynchronous reads. Typically involves setting up an interrupt handler for when conversion is done, and
* possibly calibration. */
void setupMozziADC(int8_t speed) {
#warning Fast analog read not implemented on this platform
IRQManager::getInstance().addADCScanEnd(&adc, NULL); // this is needed to change some config inside the ADC, even though we do not give the callback here (doing so crashes the board). The callback is declared to the ADC by: R_ADC_CallbackSet(&(_adc->ctrl), adc_callback, p_context, p_callback_memory); in MozziGuts_impl_RENESAS_ADC.hpp.
}

/* NOTE: Most platforms call a specific function/ISR when conversion is complete. Provide this function, here.
* From inside its body, simply call advanceADCStep(). E.g.:
void stm32_adc_eoc_handler() {
advanceADCStep();
}
*/

////// END analog input code ////////


Expand Down
36 changes: 36 additions & 0 deletions MozziGuts_impl_RENESAS_ADC.hpp
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;
}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,11 @@ port by Thomas Combriat
Compiles and runs using Arduino's standard library (Renesas 0.8.7 at the time of this writing).

- A few particularities:
- Because this board has an on-board DAC (A0), but only one, STEREO is not implemented and Mozzi uses only this pin. Usage of other pins using PWM for instance is not implemented.
- Two timers are claimed by Mozzi when using the on-board DAC, one when using `EXTERNAL_AUDIO_OUTPUT`.

- Because this board has an on-board DAC (A0), but only one, STEREO is not implemented and Mozzi uses this pin. Usage of other pins using PWM for instance is not implemented yet.
- Two timers are claimed by Mozzi when using the on-board DAC, one when using `EXTERNAL_AUDIO_OUTPUT`.
- `mozziAnalogRead()` returns values in the Renesas' full ADC resolution of 0-16384 rather than AVR's 0-1023. *This might change in the near future for speed purposes.*


***

Expand Down

0 comments on commit 39fb92c

Please sign in to comment.