Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion battery_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// License: MIT
//

#include "hardware.h"
#include "hardware/adc.h"
#include "pico/stdlib.h"
#include <stdio.h>
Expand All @@ -27,7 +28,7 @@ int main() {
uint8_t batt_adc = 3;
uint8_t temp_adc = 4;
adc_init();
adc_gpio_init(29);//Battery - configure pin for ADC use
adc_gpio_init(PIN_ADC_BATT);//Battery - configure pin for ADC use
adc_set_temp_sensor_enabled(true);
adc_set_clkdiv(0); //flat out

Expand Down
45 changes: 45 additions & 0 deletions hardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef __hardware_h__
#define __hardware_h__

#define PSU_PIN 23
#define AUDIO_PIN 16

#define PIN_NCO_I 0
#define PIN_NCO_Q 1
// todo - nco.pio
// quadrature_encoder.pio

#define PIN_ADC_I 26
#define PIN_ADC_Q 27
#define PIN_ADC_BATT 29
// todo - adc_select_input calls
// battery_check.cpp
// rx.cpp

#define PIN_VBUS 24

#define PIN_BAND_A 2
#define PIN_BAND_B 3
#define PIN_BAND_C 4

#define PIN_AB 20
#define PIN_B 21
#define PIN_MENU 22
#define PIN_BACK 17
#define PIN_ENCODER_PUSH 5

#define I2C_SDA_PIN 18
#define I2C_SCL_PIN 19
#define I2C_INST (i2c1)
#define I2C_SPEED (400UL)

#define PIN_MISO 12
#define PIN_CS 13
#define PIN_SCK 14
#define PIN_MOSI 15
#define PIN_DC 11
#define PIN_RST 10
#define SPI_PORT spi1


#endif
81 changes: 41 additions & 40 deletions rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <algorithm>

#include "hardware.h"
#include "rx.h"
#include "nco.h"
#include "fft_filter.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ void rx::pwm_ramp_down()
level = std::min(level, (int16_t)pwm_max);
level = std::max(level, (int16_t)0);
phase += phase_increment;
pwm_set_gpio_level(16, level);
pwm_set_gpio_level(AUDIO_PIN, level);
}
}

Expand All @@ -116,7 +117,7 @@ void rx::pwm_ramp_up()
level = std::min(level, (int16_t)pwm_max);
level = std::max(level, (int16_t)0);
phase += phase_increment;
pwm_set_gpio_level(16, level);
pwm_set_gpio_level(AUDIO_PIN, level);
}
}

Expand Down Expand Up @@ -156,51 +157,51 @@ void rx::apply_settings()

if(tuned_frequency_Hz > (settings_to_apply.band_7_limit * 125000))
{
gpio_put(2, 0);
gpio_put(3, 0);
gpio_put(4, 0);
gpio_put(PIN_BAND_A, 0);
gpio_put(PIN_BAND_B, 0);
gpio_put(PIN_BAND_C, 0);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_6_limit * 125000))
{
gpio_put(2, 1);
gpio_put(3, 0);
gpio_put(4, 0);
gpio_put(PIN_BAND_A, 1);
gpio_put(PIN_BAND_B, 0);
gpio_put(PIN_BAND_C, 0);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_5_limit * 125000))
{
gpio_put(2, 0);
gpio_put(3, 1);
gpio_put(4, 0);
gpio_put(PIN_BAND_A, 0);
gpio_put(PIN_BAND_B, 1);
gpio_put(PIN_BAND_C, 0);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_4_limit * 125000))
{
gpio_put(2, 1);
gpio_put(3, 1);
gpio_put(4, 0);
gpio_put(PIN_BAND_A, 1);
gpio_put(PIN_BAND_B, 1);
gpio_put(PIN_BAND_C, 0);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_3_limit * 125000))
{
gpio_put(2, 0);
gpio_put(3, 0);
gpio_put(4, 1);
gpio_put(PIN_BAND_A, 0);
gpio_put(PIN_BAND_B, 0);
gpio_put(PIN_BAND_C, 1);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_2_limit * 125000))
{
gpio_put(2, 1);
gpio_put(3, 0);
gpio_put(4, 1);
gpio_put(PIN_BAND_A, 1);
gpio_put(PIN_BAND_B, 0);
gpio_put(PIN_BAND_C, 1);
}
else if(tuned_frequency_Hz > (settings_to_apply.band_1_limit * 125000))
{
gpio_put(2, 0);
gpio_put(3, 1);
gpio_put(4, 1);
gpio_put(PIN_BAND_A, 0);
gpio_put(PIN_BAND_B, 1);
gpio_put(PIN_BAND_C, 1);
}
else
{
gpio_put(2, 1);
gpio_put(3, 1);
gpio_put(4, 1);
gpio_put(PIN_BAND_A, 1);
gpio_put(PIN_BAND_B, 1);
gpio_put(PIN_BAND_C, 1);
}

//apply pwm_max
Expand Down Expand Up @@ -278,30 +279,30 @@ rx::rx(rx_settings & settings_to_apply, rx_status & status) : settings_to_apply(
ring_buffer_init(&usb_ring_buffer, usb_buf, USB_BUF_SIZE, 1);

//configure SMPS into power save mode
const uint PSU_PIN = 23;
// const uint PSU_PIN = 23;
gpio_init(PSU_PIN);
gpio_set_function(PSU_PIN, GPIO_FUNC_SIO);
gpio_set_dir(PSU_PIN, GPIO_OUT);
gpio_put(PSU_PIN, 1);

//ADC Configuration
adc_init();
adc_gpio_init(26);//I channel (0) - configure pin for ADC use
adc_gpio_init(27);//Q channel (1) - configure pin for ADC use
adc_gpio_init(29);//Battery - configure pin for ADC use
adc_gpio_init(PIN_ADC_I);//I channel (0) - configure pin for ADC use
adc_gpio_init(PIN_ADC_Q);//Q channel (1) - configure pin for ADC use
adc_gpio_init(PIN_ADC_BATT);//Battery - configure pin for ADC use
adc_set_temp_sensor_enabled(true);
adc_set_clkdiv(99); //48e6/480e3

//band select
gpio_init(2);//band 0
gpio_init(3);//band 1
gpio_init(4);//band 2
gpio_set_function(2, GPIO_FUNC_SIO);
gpio_set_function(3, GPIO_FUNC_SIO);
gpio_set_function(4, GPIO_FUNC_SIO);
gpio_set_dir(2, GPIO_OUT);
gpio_set_dir(3, GPIO_OUT);
gpio_set_dir(4, GPIO_OUT);
gpio_init(PIN_BAND_A);//band 0
gpio_init(PIN_BAND_B);//band 1
gpio_init(PIN_BAND_C);//band 2
gpio_set_function(PIN_BAND_A, GPIO_FUNC_SIO);
gpio_set_function(PIN_BAND_B, GPIO_FUNC_SIO);
gpio_set_function(PIN_BAND_C, GPIO_FUNC_SIO);
gpio_set_dir(PIN_BAND_A, GPIO_OUT);
gpio_set_dir(PIN_BAND_B, GPIO_OUT);
gpio_set_dir(PIN_BAND_C, GPIO_OUT);

// Configure DMA for ADC transfers
adc_dma_ping = dma_claim_unused_channel(true);
Expand All @@ -325,7 +326,7 @@ rx::rx(rx_settings & settings_to_apply, rx_status & status) : settings_to_apply(
sem_init(&settings_semaphore, 1, 1);

//audio output
const uint AUDIO_PIN = 16;
// const uint AUDIO_PIN = 16;
gpio_set_function(AUDIO_PIN, GPIO_FUNC_PWM);
gpio_set_drive_strength(AUDIO_PIN, GPIO_DRIVE_STRENGTH_12MA);
audio_pwm_slice_num = pwm_gpio_to_slice_num(AUDIO_PIN);
Expand Down
27 changes: 15 additions & 12 deletions ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <float.h>
#include <math.h>

#include "hardware.h"
#include "pico/multicore.h"
#include "ui.h"
#include "fft_filter.h"
Expand Down Expand Up @@ -261,7 +262,7 @@ void ui::display_draw_battery(float v, uint8_t x)
u8g2_DrawHLine(&u8g2, x+0, 13, 14);


const bool vbus_present = gpio_get(24);
const bool vbus_present = gpio_get(PIN_VBUS);

if(vbus_present)
{
Expand Down Expand Up @@ -2249,8 +2250,8 @@ bool ui::configuration_menu(bool &ok)

case 1 :
done = enumerate_entry("PSU Mode", "FM#PWM#", &regmode, ok, changed);
gpio_set_dir(23, GPIO_OUT);
gpio_put(23, regmode);
gpio_set_dir(PSU_PIN, GPIO_OUT);
gpio_put(PSU_PIN, regmode);
break;

case 2 :
Expand Down Expand Up @@ -2787,10 +2788,12 @@ void ui::do_ui()
}
}

/*
#define OLED_I2C_SDA_PIN (18)
#define OLED_I2C_SCL_PIN (19)
#define OLED_I2C_SPEED (400UL)
#define OLED_I2C_INST (i2c1)
*/

static uint8_t u8x8_gpio_and_delay_pico(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
Expand Down Expand Up @@ -2839,11 +2842,11 @@ static uint8_t u8x8_byte_pico_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
break;

case U8X8_MSG_BYTE_INIT:
i2c_init(OLED_I2C_INST, OLED_I2C_SPEED * 1000);
gpio_set_function(OLED_I2C_SDA_PIN, GPIO_FUNC_I2C);
gpio_set_function(OLED_I2C_SCL_PIN, GPIO_FUNC_I2C);
gpio_pull_up(OLED_I2C_SDA_PIN);
gpio_pull_up(OLED_I2C_SCL_PIN);
i2c_init(I2C_INST, I2C_SPEED * 1000);
gpio_set_function(I2C_SDA_PIN, GPIO_FUNC_I2C);
gpio_set_function(I2C_SCL_PIN, GPIO_FUNC_I2C);
gpio_pull_up(I2C_SDA_PIN);
gpio_pull_up(I2C_SCL_PIN);
break;

case U8X8_MSG_BYTE_SET_DC:
Expand All @@ -2856,7 +2859,7 @@ static uint8_t u8x8_byte_pico_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int,
case U8X8_MSG_BYTE_END_TRANSFER:
{
uint8_t addr = u8x8_GetI2CAddress(u8x8) >> 1;
int ret = i2c_write_blocking(OLED_I2C_INST, addr, buffer, buf_idx, false);
int ret = i2c_write_blocking(I2C_INST, addr, buffer, buf_idx, false);
if ((ret == PICO_ERROR_GENERIC) || (ret == PICO_ERROR_TIMEOUT))
{
return 0;
Expand Down Expand Up @@ -2894,9 +2897,9 @@ ui::ui(rx_settings & settings_to_apply, rx_status & status, rx &receiver, uint8_
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0,
u8x8_byte_pico_hw_i2c,
u8x8_gpio_and_delay_pico);
gpio_init(24);
gpio_set_dir(24, GPIO_IN);
gpio_pull_down(24);
gpio_init(PIN_VBUS);
gpio_set_dir(PIN_VBUS, GPIO_IN);
gpio_pull_down(PIN_VBUS);

setup_display();
setup_encoder();
Expand Down
3 changes: 3 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstdint>

#include "hardware.h"
#include "pico/bootrom.h"
#include "hardware/i2c.h"
#include "quadrature_encoder.pio.h"
Expand All @@ -22,13 +23,15 @@
#define M_PI 3.14159265
#endif

/*
const uint8_t PIN_AB = 20;
const uint8_t PIN_B = 21;
const uint8_t PIN_MENU = 22;
const uint8_t PIN_BACK = 17;
const uint8_t PIN_ENCODER_PUSH = 5;
const uint8_t PIN_DISPLAY_SDA = 18;
const uint8_t PIN_DISPLAY_SCL = 19;
*/

#define MODE_AM 0
#define MODE_AMS 1
Expand Down
3 changes: 3 additions & 0 deletions waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cmath>
#include <cstdio>

#include "hardware.h"
#include "pico/stdlib.h"
#include "hardware/spi.h"
#include "fft_filter.h"
Expand All @@ -17,6 +18,7 @@ waterfall::waterfall()
//using ili9341 library from here:
//https://github.com/bizzehdee/pico-libs

/*
#define PIN_MISO 12
#define PIN_CS 13
#define PIN_SCK 14
Expand All @@ -25,6 +27,7 @@ waterfall::waterfall()
#define PIN_RST 10
#define SPI_PORT spi1
//spi_init(SPI_PORT, 62500000);
*/
spi_init(SPI_PORT, 40000000);
gpio_set_function(PIN_MISO, GPIO_FUNC_SPI);
gpio_set_function(PIN_SCK, GPIO_FUNC_SPI);
Expand Down