Code maintenance

main
eleccoder 2022-12-22 21:41:30 +01:00
rodzic 61462ae469
commit 9fcdbd51c2
3 zmienionych plików z 19 dodań i 23 usunięć

Wyświetl plik

@ -13,16 +13,15 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef APRS_PICO_H #pragma once
#define APRS_PICO_H
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <pico/audio_pwm.h> // For 'audio_buffer_pool_t' #include "pico/audio_pwm.h" // For 'audio_buffer_pool_t'
/** \brief Initializes the APRS Pico library /** \brief Initializes the APRS Pico library
@ -69,5 +68,3 @@ bool aprs_pico_sendAPRS(audio_buffer_pool_t* audio_buffer_pool,
* \param[in] volume The volume level of the generated signal (0 ... 256) * \param[in] volume The volume level of the generated signal (0 ... 256)
*/ */
void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, unsigned int sample_freq_in_hz, uint16_t volume); void aprs_pico_send_sine_wave(audio_buffer_pool_t* audio_buffer_pool, unsigned int freq_in_hz, unsigned int sample_freq_in_hz, uint16_t volume);
#endif // APRS_PICO_H

Wyświetl plik

@ -13,22 +13,21 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <aprs_pico.h> #include "aprs_pico.h"
#include "ax25beacon.h"
#include "pico/stdlib.h"
#include <stdio.h>
#include <math.h> #include <math.h>
#include <pico/stdlib.h>
#include <ax25beacon.h>
// NOTE: ATTOW, the pico-extra audio PWM lib worked only at a fixed 22050 Hz sampling frequency, while the
// WARNING: ATTOW, the pico audio PWM lib worked only @ 22050 Hz sampling frequency and 48 MHz system clock // system clock runs at 48 MHz. This is documented here: https://github.com/raspberrypi/pico-extras
// This is documented here: https://github.com/raspberrypi/pico-extras #define APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__FIXED_SAMPLE_FREQ_IN_HZ (22050)
#define APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB_FIXED_SAMPLE_FREQ_IN_HZ (22050) #define APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__SYS_CLOCK_FREQ_OF_IN_MHZ (48)
#define APRS_PICO__SYS_CLOCK_FREQ_OF_PICO_EXTRA_AUDIO_PWM_LIB_IN_MHZ (48)
typedef struct AudioCallBackUserData typedef struct AudioCallBackUserData
@ -81,14 +80,14 @@ static audio_buffer_pool_t* aprs_pico_initAudio(unsigned int sample_freq_in_hz,
*/ */
static void aprs_pico_initClock(unsigned int sample_freq_in_hz) static void aprs_pico_initClock(unsigned int sample_freq_in_hz)
{ {
// WARNING: ATTOW, the pico audio PWM lib worked only @ 22050 Hz sampling frequency and 48 MHz system clock // NOTE: ATTOW, the pico-extra audio PWM lib worked only at a fixed 22050 Hz sampling frequency, while the
// This is documented here: https://github.com/raspberrypi/pico-extras // system clock runs at 48 MHz. This is documented here: https://github.com/raspberrypi/pico-extras
// Compensate a non-'PICO_EXTRA_AUDIO_PWM_LIB_FIXED_SAMPLE_FREQ_IN_HZ' sampling frequency // Compensate a non-'APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__FIXED_SAMPLE_FREQ_IN_HZ' sampling frequency
// by adapting the system clock accordingly // by adapting the system clock frequency accordingly.
float sys_clock_in_mhz = (float)APRS_PICO__SYS_CLOCK_FREQ_OF_PICO_EXTRA_AUDIO_PWM_LIB_IN_MHZ * float sys_clock_in_mhz = (float)APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__SYS_CLOCK_FREQ_OF_IN_MHZ *
((float)sample_freq_in_hz / (float)APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB_FIXED_SAMPLE_FREQ_IN_HZ); ((float)sample_freq_in_hz / (float)APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__FIXED_SAMPLE_FREQ_IN_HZ);
if (!set_sys_clock_khz((uint32_t)(1000.0f * sys_clock_in_mhz), false)) if (!set_sys_clock_khz((uint32_t)(1000.0f * sys_clock_in_mhz), false))
{ {
@ -177,7 +176,7 @@ static void aprs_pico_sendAPRSAudioCallback(const void* callback_user_data, cons
// See the header file for documentation // See the header file for documentation
audio_buffer_pool_t* aprs_pico_init() audio_buffer_pool_t* aprs_pico_init()
{ {
audio_buffer_pool_t* audio_buffer_pool = aprs_pico_initAudio(APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB_FIXED_SAMPLE_FREQ_IN_HZ, audio_buffer_pool_t* audio_buffer_pool = aprs_pico_initAudio(APRS_PICO__PICO_EXTRA_AUDIO_PWM_LIB__FIXED_SAMPLE_FREQ_IN_HZ,
AUDIO_BUFFER_FORMAT_PCM_S16); AUDIO_BUFFER_FORMAT_PCM_S16);
return audio_buffer_pool; return audio_buffer_pool;
} }