finish abstraction for RPi

This commit is contained in:
morgan 2019-02-02 21:13:21 +00:00
parent f7c76eb1ad
commit 844bb6b8c6
3 changed files with 27 additions and 10 deletions

View File

@ -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_LOW
* @see A1846S_ADDRESS_AD0_HIGH * @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; devAddr = cs_pin;
hs_pwm_pin = pwm_pin; hs_pwm_pin = pwm_pin;

View File

@ -4,10 +4,6 @@
#include "HamShield_comms.h" #include "HamShield_comms.h"
#include "Arduino.h"
//#include "I2Cdev.h"
uint8_t ncs_pin = nSEN; uint8_t ncs_pin = nSEN;
uint8_t clk_pin = CLK; uint8_t clk_pin = CLK;
uint8_t dat_pin = DAT; uint8_t dat_pin = DAT;
@ -16,6 +12,10 @@ void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat) {
ncs_pin = ncs; ncs_pin = ncs;
clk_pin = clk; clk_pin = clk;
dat_pin = dat; dat_pin = dat;
#if !defined(ARDUINO)
wiringPiSetup();
#endif
pinMode(ncs_pin, OUTPUT); pinMode(ncs_pin, OUTPUT);
digitalWrite(ncs_pin, HIGH); digitalWrite(ncs_pin, HIGH);
@ -147,11 +147,17 @@ void HSdelayMicroseconds(unsigned int us) {
} }
void HStone(uint8_t pin, unsigned int frequency) { void HStone(uint8_t pin, unsigned int frequency) {
#if defined(ARDUINO)
tone(pin, frequency); tone(pin, frequency);
} #else
void HStone(uint8_t pin, unsigned int frequency, unsigned long duration) { softToneCreate(pin);
tone(pin, frequency, duration); softToneWrite(pin, frequency);
#endif
} }
void HSnoTone(uint8_t pin) { void HSnoTone(uint8_t pin) {
#if defined(ARDUINO)
noTone(pin); noTone(pin);
#else
softToneWrite(pin, 0);
#endif
} }

View File

@ -4,13 +4,24 @@
#ifndef _HAMSHIELD_COMMS_H_ #ifndef _HAMSHIELD_COMMS_H_
#define _HAMSHIELD_COMMS_H_ #define _HAMSHIELD_COMMS_H_
#include "stdint.h"
#if defined(ARDUINO)
#include "Arduino.h" #include "Arduino.h"
#define nSEN A1 //15 // #define nSEN A1 //15 //
#define CLK A5 //19 // #define CLK A5 //19 //
#define DAT A4 //18 // #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 <wiringPi.h>
#include <softTone.h>
#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); void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat);