From 844bb6b8c602875629810430aa66463cd6fa6d0d Mon Sep 17 00:00:00 2001 From: morgan Date: Sat, 2 Feb 2019 21:13:21 +0000 Subject: [PATCH] finish abstraction for RPi --- src/HamShield.cpp | 2 +- src/HamShield_comms.cpp | 20 +++++++++++++------- src/HamShield_comms.h | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 1c8c196..0a9b5cb 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -125,7 +125,7 @@ const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, * @see A1846S_ADDRESS_AD0_LOW * @see A1846S_ADDRESS_AD0_HIGH */ -HamShield::HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT, uint8_t pwm_pin = HAMSHIELD_PWM_PIN) { +HamShield::HamShield(uint8_t cs_pin, uint8_t clk_pin, uint8_t dat_pin, uint8_t pwm_pin) { devAddr = cs_pin; hs_pwm_pin = pwm_pin; diff --git a/src/HamShield_comms.cpp b/src/HamShield_comms.cpp index 9738d37..5b1889b 100644 --- a/src/HamShield_comms.cpp +++ b/src/HamShield_comms.cpp @@ -4,10 +4,6 @@ #include "HamShield_comms.h" - -#include "Arduino.h" -//#include "I2Cdev.h" - uint8_t ncs_pin = nSEN; uint8_t clk_pin = CLK; uint8_t dat_pin = DAT; @@ -16,6 +12,10 @@ void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat) { ncs_pin = ncs; clk_pin = clk; dat_pin = dat; + +#if !defined(ARDUINO) + wiringPiSetup(); +#endif pinMode(ncs_pin, OUTPUT); digitalWrite(ncs_pin, HIGH); @@ -147,11 +147,17 @@ void HSdelayMicroseconds(unsigned int us) { } void HStone(uint8_t pin, unsigned int frequency) { +#if defined(ARDUINO) tone(pin, frequency); -} -void HStone(uint8_t pin, unsigned int frequency, unsigned long duration) { - tone(pin, frequency, duration); +#else + softToneCreate(pin); + softToneWrite(pin, frequency); +#endif } void HSnoTone(uint8_t pin) { +#if defined(ARDUINO) noTone(pin); +#else + softToneWrite(pin, 0); +#endif } \ No newline at end of file diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index 8993a28..8406228 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -4,13 +4,24 @@ #ifndef _HAMSHIELD_COMMS_H_ #define _HAMSHIELD_COMMS_H_ -#include "stdint.h" +#if defined(ARDUINO) #include "Arduino.h" + #define nSEN A1 //15 // #define CLK A5 //19 // #define DAT A4 //18 // -#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output +#define HAMSHIELD_PWM_PIN 3 +#else // assume Raspberry Pi +#include "stdint.h" +#include +#include + +#define nSEN 17 // +#define CLK 22 // +#define DAT 27 // +#define HAMSHIELD_PWM_PIN 18 +#endif void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat);