start to clean up tone

This commit is contained in:
hathach committed 2020-08-25 16:46:26 +07:00
1 parent 019b1c248e
commit cca5adaa51
3 files changed
+20 -88

No files matched your search

-68
View File
@@ -1,68 +0,0 @@
sudo: required
language: c
dist: xenial
git:
depth: false
quiet: true
env:
global:
- BSP_PATH="$HOME/.arduino15/packages/adafruit/hardware/nrf52"
jobs:
# empty env required, else allow_failures will SILENTY IGNORE matching against env...
-
jobs:
fast_finish: true
include:
- name: "Feather nRF52840"
env: VARIANT="feather52840"
- name: "Feather nRF52840 (All warnings)"
env: ALL_WARNINGS="true" VARIANT="feather52840"
- name: "Circuit Playground nRF52840"
env: VARIANT="cplaynrf52840"
- name: "Circuit Playground nRF52840 (All warnings)"
env: ALL_WARNINGS="true" VARIANT="cplaynrf52840"
- name: "Feather nRF52832"
env: VARIANT="feather52832"
- name: "Feather nRF52832 (All warnings)"
env: ALL_WARNINGS="true" VARIANT="feather52832"
- name: "ItsyBitsy nRF52840 Express"
env: VARIANT="itsybitsy52840"
- name: "Clue nRF52840"
env: VARIANT="cluenrf52840"
allow_failures:
- env: ALL_WARNINGS="true" VARIANT="feather52840"
- env: ALL_WARNINGS="true" VARIANT="cplaynrf52840"
- env: ALL_WARNINGS="true" VARIANT="feather52832"
addons:
apt:
packages:
- python3
- python3-pip
- python3-setuptools
snaps:
- name: ubuntu-make
confinement: classic
install:
# Filter only mDNS / Bonjour traffic
- sudo iptables --insert INPUT --jump DROP --protocol udp --dport 5353 -m comment --comment "silently drop all 5353/udp input"
- sudo iptables --insert INPUT --jump DROP --destination 224.0.0.251 -m comment --comment "silently drop all mDNS ipv4 broadcast"
# Install the nRF52 support files for arduino
- pip3 install --user adafruit-nrfutil
- umake electronics arduino $HOME/arduino_ide
- export PATH=$HOME/arduino_ide:$PATH
- arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" --save-prefs
# Install BSP for tools, then remove and create symlink the git code
- arduino --install-boards adafruit:nrf52
- BSP_VERSION=`eval ls $BSP_PATH`
- rm -r $BSP_PATH/*
- ln -s $TRAVIS_BUILD_DIR $BSP_PATH/$BSP_VERSION
- arduino --install-library "Adafruit NeoPixel","Adafruit NeoMatrix","Adafruit GFX Library","Adafruit SSD1306","MIDI Library","Adafruit ILI9341","Adafruit HX8357 Library","Adafruit Circuit Playground"
before_script:
script:
- python3 tools/build_all_travis.py
+9 -7
View File
@@ -291,16 +291,17 @@ bool HardwarePWM::takeOwnership(uintptr_t token)
return false;
}
if (this->_owner_token != 0) return false;
if (this->usedChannelCount() != 0) return false;
if (this->enabled()) return false;
if ( this->_owner_token != 0 ) return false;
if ( this->usedChannelCount() != 0 ) return false;
if ( this->enabled() ) return false;
if (isInISR())
if ( isInISR() )
{
UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR();
_owner_token = token;
taskEXIT_CRITICAL_FROM_ISR(intr_status);
}else
}
else
{
taskENTER_CRITICAL();
_owner_token = token;
@@ -333,12 +334,13 @@ bool HardwarePWM::releaseOwnership(uintptr_t token)
return false; // if it's enabled, do not allow ownership to be released, even with no pins in use
}
if (isInISR())
if ( isInISR() )
{
UBaseType_t intr_status = taskENTER_CRITICAL_FROM_ISR();
_owner_token = 0;
taskEXIT_CRITICAL_FROM_ISR(intr_status);
}else
}
else
{
taskENTER_CRITICAL();
_owner_token = 0;
+11 -13
View File
@@ -48,22 +48,16 @@ static HardwarePWM * const _HwPWM = HwPWMx[2];
// Defined a struct, to simplify validation testing ... also provides context when debugging
class TonePwmConfig {
private:
const nrf_pwm_clk_t clock_frequency = NRF_PWM_CLK_125kHz;
const nrf_pwm_mode_t pwm_mode = NRF_PWM_MODE_UP;
const nrf_pwm_dec_step_t step_mode = NRF_PWM_STEP_AUTO;
const nrf_pwm_dec_load_t load_mode = NRF_PWM_LOAD_COMMON;
const uintptr_t toneToken = 0x656e6f54; //< 'T' 'o' 'n' 'e'
private:
uint64_t pulse_count; //< total number of PWM pulses
uint32_t seq0_refresh; //< count of pulses for each SEQ0 iteration
uint32_t seq1_refresh; //< count of pulses for each SEQ1 iteration
uint16_t loop_count; //< how many times to restart SEQ0/SEQ1?
uint16_t time_period; //< how many clock cycles allocated to each PWM pulse?
uint16_t duty_with_polarity; //< SEQ[N].PTR will point here, length == 1
uint8_t arduino_pin; //< the arduino pin for playback
uint8_t nrf_pin; //< the nrf pin for playback
nrf_pwm_task_t task_to_start; //< Whether to start playback at SEQ0 or SEQ1
nrf_pwm_short_mask_t shorts; //< shortcuts to enable
public:
bool ensurePwmPeripheralOwnership(void);
bool initializeFromPulseCountAndTimePeriod(uint64_t pulse_count, uint16_t time_period);
@@ -98,6 +92,7 @@ constexpr static uint16_t _calculate_time_period(uint32_t frequency) {
// which fits in 16 bits.
return 125000 / frequency;
};
constexpr static uint64_t _calculate_pulse_count(uint32_t frequency, uint32_t duration) {
// range for frequency == [20..25000],
// range for duration == [ 1..0xFFFF_FFFF]
@@ -111,6 +106,7 @@ constexpr static uint64_t _calculate_pulse_count(uint32_t frequency, uint32_t du
(duration / 1000ULL) * frequency :
(((uint64_t)duration) * frequency / 1000ULL);
};
static int _bits_used(unsigned long x) {
if (0 == x) return 0;
unsigned int result = 0;
@@ -119,6 +115,7 @@ static int _bits_used(unsigned long x) {
} while (x >>= 1);
return result;
}
static int _bits_used(unsigned long long x) {
if (0 == x) return 0;
unsigned int result = 0;
@@ -193,6 +190,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
}
return;
}
void noTone(uint8_t pin)
{
( void )pin; // avoid unreferenced parameter compiler warning
@@ -310,6 +308,7 @@ bool TonePwmConfig::initializeFromPulseCountAndTimePeriod(uint64_t pulse_count_x
}
return true;
}
bool TonePwmConfig::applyConfiguration(uint32_t pin) {
if (pin >= PINS_COUNT) {
return false;
@@ -319,11 +318,8 @@ bool TonePwmConfig::applyConfiguration(uint32_t pin) {
}
this->stopPlayback(false);
this->arduino_pin = pin;
this->nrf_pin = g_ADigitalPinMap[pin];
uint32_t pins[NRF_PWM_CHANNEL_COUNT] = {
this->nrf_pin,
g_ADigitalPinMap[pin],
NRF_PWM_PIN_NOT_CONNECTED,
NRF_PWM_PIN_NOT_CONNECTED,
NRF_PWM_PIN_NOT_CONNECTED
@@ -331,8 +327,8 @@ bool TonePwmConfig::applyConfiguration(uint32_t pin) {
nrf_pwm_pins_set(_PWMInstance, pins); // must set pins before enabling
nrf_pwm_enable(_PWMInstance);
nrf_pwm_configure(_PWMInstance, TonePwmConfig::clock_frequency, TonePwmConfig::pwm_mode, this->time_period);
nrf_pwm_decoder_set(_PWMInstance, TonePwmConfig::load_mode, TonePwmConfig::step_mode);
nrf_pwm_configure(_PWMInstance, NRF_PWM_CLK_125kHz, NRF_PWM_MODE_UP, this->time_period);
nrf_pwm_decoder_set(_PWMInstance, NRF_PWM_LOAD_COMMON, NRF_PWM_STEP_AUTO);
nrf_pwm_shorts_set(_PWMInstance, this->shorts);
nrf_pwm_int_set(_PWMInstance, 0);
@@ -362,6 +358,7 @@ bool TonePwmConfig::applyConfiguration(uint32_t pin) {
nrf_pwm_event_clear(_PWMInstance, NRF_PWM_EVENT_LOOPSDONE);
return true;
}
bool TonePwmConfig::startPlayback(void) {
if (!this->ensurePwmPeripheralOwnership()) {
LOG_LV1("TON", "PWM peripheral not available for playback");
@@ -370,6 +367,7 @@ bool TonePwmConfig::startPlayback(void) {
nrf_pwm_task_trigger(_PWMInstance, this->task_to_start);
return true;
}
bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
bool notInIsr = !isInISR();