diff --git a/Makefile b/Makefile index 8501528..96e4a5e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -#select target. supported: {VD5M, D4RII, USKY, TINYFISH, AFRX, RASP} +#select target. supported: {VD5M, D4RII, USKY, TINYFISH, AFRX, RASP, ARDUINO} TARGET ?= USKY ASFLAGS = -g diff --git a/arch/atmega328/atmega328.mk b/arch/atmega328/atmega328.mk new file mode 100644 index 0000000..1781526 --- /dev/null +++ b/arch/atmega328/atmega328.mk @@ -0,0 +1,101 @@ +# object files +HAL_SRCS = \ + hal_uart.c \ + hal_timeout.c \ + hal_wdt.c \ + hal_clocksource.c \ + hal_spi.c \ + hal_cc25xx.c \ + hal_io.c \ + hal_adc.c \ + hal_storage.c \ + hal_ppm.c \ + hal_soft_spi.c \ + hal_soft_serial.c + +ALL_SRCS = $(HAL_SRCS) $(GENERIC_SRCS) + +# fetch this dir during include +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + +# include path +CFLAGS += -I$(SELF_DIR) + +# Tool path, only override if not set +TOOLROOT ?= /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin + +# Tools +CC=$(TOOLROOT)/avr-gcc +LD=$(TOOLROOT)/avr-gcc +AR=$(TOOLROOT)/avr-gcc-ar +AS=$(TOOLROOT)/avr-as +OBJ=$(TOOLROOT)/avr-objcopy +SIZE=$(TOOLROOT)/avr-size +AVRDUDE=$(TOOLROOT)/avrdude + +# Code Paths +ARCH_DIR=arch/atmega328 + +INCLUDE_DIRS := $(INCLUDE_DIRS) \ + $(SRC_DIR) \ + $(ARCH_DIR) \ + $(TARGET_DIR) + +# Search path for standard files +vpath %.c ./ +vpath %.c $(ARCH_DIR) + +LDFLAGS+= $(BOARD_FLAGS) -Wl,--gc-sections -Os -flto -fuse-linker-plugin +CFLAGS+= $(BOARD_FLAGS) -std=gnu11 -Os -flto -fno-fat-lto-objects +CFLAGS+= -I. -I$(ARCH_DIR) +CFLAGS+= -DBUILD_TARGET=$(TARGET) +CFLAGS+= $(addprefix -I,$(INCLUDE_DIRS)) + +TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(ALL_SRCS)))) +TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(ALL_SRCS)))) +TARGET_ELF = $(OBJECT_DIR)/$(RESULT).elf +TARGET_HEX = $(OBJECT_DIR)/$(RESULT).hex +TARGET_EEP = $(OBJECT_DIR)/$(RESULT).eep +TARGET_LST = $(OBJECT_DIR)/$(RESULT).lst + +# Build executable +board: $(TARGET_HEX) + +$(TARGET_ELF): $(TARGET_OBJS) + $(V1) exit + $(V1) echo Linking: $(TARGET) + $(V1) $(LD) -o $@ $^ $(LDFLAGS) + $(V0) $(SIZE) $(TARGET_ELF) + $(OBJ) -j .eeprom --set-section-flags=.eeprom='alloc,load' \ + --no-change-warnings --change-section-lma .eeprom=0 -O ihex $(TARGET_ELF) $(TARGET_EEP) + $(SIZE) --mcu=$(BOARD_NAME) -C --format=avr $(TARGET_ELF) + +$(TARGET_HEX): $(TARGET_ELF) + $(OBJ) -O ihex -R .eeprom $(TARGET_ELF) $(TARGET_HEX) + +$(TARGET_LST): $(TARGET_ELF) + $(DUMP) -h -S $(TARGET_ELF) > $(TARGET_LST) + +$(OBJECT_DIR)/$(TARGET)/%.o: %.c + $(V1) mkdir -p $(dir $@) + $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \ + $(CC) -c -o $@ $(CFLAGS) $< + +$(OBJECT_DIR)/$(TARGET)/%.o: %.s + $(V1) mkdir -p $(dir $@) + $(V1) echo "%% $(notdir $<)" "$(STDOUT)" + $(V1) $(CC) -c $(CFLAGS) $(DEPFLAGS) $< -o $@ + +clean: + $(V1) echo Cleaning: $(TARGET) + $(V1) rm -f $(OBJECT_DIR)/$(TARGET)/src/*.o $(OBJECT_DIR)/$(TARGET)/src/*.d $(OBJECT_DIR)/$(TARGET)/*.o $(OBJECT_DIR)/$(TARGET)/*.d $(OBJECT_DIR)/*.elf $(OBJECT_DIR)/*.bin $(OBJECT_DIR)/*.hex $(OBJECT_DIR)/*.eep + +flash: $(TARGET_HEX) + $(AVRDUDE) -q -V -p $(BOARD_NAME) \ + -C $(TOOLROOT)/../etc/avrdude.conf \ + -D -c arduino -b $(SERIAL_SPEED) -P $(SERIAL_PORT) \ + -U flash:w:$^:i + +.PHONY: board clean flash debug + + diff --git a/src/spi.c b/arch/atmega328/hal_adc.c similarity index 66% rename from src/spi.c rename to arch/atmega328/hal_adc.c index 1616684..558d99f 100644 --- a/src/spi.c +++ b/arch/atmega328/hal_adc.c @@ -1,6 +1,4 @@ /* - Copyright 2017 fishpepper gmail.com - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -12,16 +10,20 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . - author: fishpepper gmail.com + author: fishpepper gmail.com, jimmyw github */ -#include "spi.h" -#include "hal_spi.h" -#include "debug.h" +#include "hal_adc.h" + +void hal_adc_init(void) { +} + +uint8_t hal_adc_get_scaled(uint8_t ch) { + return ch; +} -void spi_init(void) { - debug("spi: init\n"); debug_flush(); - hal_spi_init(); +void hal_adc_process(void) { } + diff --git a/arch/atmega328/hal_adc.h b/arch/atmega328/hal_adc.h new file mode 100644 index 0000000..f34e26e --- /dev/null +++ b/arch/atmega328/hal_adc.h @@ -0,0 +1,13 @@ +#ifndef __HAL_ADC_H__ +#define __HAL_ADC_H__ +#include "main.h" +#include + +extern volatile uint16_t hal_adc_data[2]; + +void hal_adc_init(void); + +uint8_t hal_adc_get_scaled(uint8_t ch); +void hal_adc_process(void); + +#endif diff --git a/arch/atmega328/hal_cc25xx.c b/arch/atmega328/hal_cc25xx.c new file mode 100644 index 0000000..03056d9 --- /dev/null +++ b/arch/atmega328/hal_cc25xx.c @@ -0,0 +1,267 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_cc25xx.h" +#include "hal_spi.h" +#include "hal_io.h" +#include "cc25xx.h" +#include "debug.h" +#include "timeout.h" +#include + +void hal_cc25xx_init(void){ + hal_spi_init(); +} + +inline uint32_t hal_cc25xx_set_antenna(uint8_t id){ + return id; +} + +inline void hal_cc25xx_set_gdo_mode(void) { + cc25xx_set_register(IOCFG0, 0x01); //6); + //cc25xx_set_register(IOCFG1, ???); + cc25xx_set_register(IOCFG2, 0x01); //6); +} + +inline void hal_cc25xx_set_register(uint8_t address, uint8_t data){ + //select device + hal_spi_csn_lo(); + + //wait for ready signal + hal_io_wait_miso_low(); + + hal_spi_tx(address); + hal_spi_tx(data); + //debug("hal_cc25xx_set_register address: 0x"); debug_put_hex8(address); debug(" data: 0x"); debug_put_hex8(data); debug("\n"); debug_flush(); + + //deslect + hal_spi_csn_hi(); + // TO VERIFY + // if (hal_cc25xx_get_register(address) != data) while(1) do debug("FAIL"); +} + +inline uint8_t hal_cc25xx_get_register(uint8_t address){ + uint8_t result; + + //select device: + hal_spi_csn_lo(); + + //wait for RDY signal: + hal_io_wait_miso_low(); + + //request address (read request has bit7 set) + uint8_t status = hal_spi_tx(address | 0x80); + + //fetch result: + result = hal_spi_rx(); + //debug("hal_cc25xx_get_register: 0x"); debug_put_hex8(address & ~(READ_FLAG | BURST_FLAG)); + //if (address & READ_FLAG) debug(" READ"); + //if (address & BURST_FLAG) debug(" BURST"); + //debug(" got: 0x"); debug_put_hex8(result); debug("\n"); + + //deselect device + hal_spi_csn_hi(); + + //return result + return(result); +} + +inline void hal_cc25xx_strobe(uint8_t address){ + hal_spi_csn_lo(); + uint8_t status = hal_spi_tx(address); + //debug("strobe: 0x"); debug_put_hex8(address); debug(" status: 0x"); debug_put_hex8(status); debug_put_newline(); + hal_spi_csn_hi(); +} + +inline uint8_t hal_cc25xx_get_status(void) { + hal_spi_csn_lo(); + uint8_t status = hal_spi_tx(0xFF); + hal_spi_csn_hi(); + return status; +} + +uint8_t hal_cc25xx_transmission_completed(void) { + //after tx cc25xx goes back to RX (configured by mcsm1 register) + return ((hal_cc25xx_get_status() & (0x70)) == CC2500_STATUS_STATE_RX); +} + +inline void hal_cc25xx_enter_rxmode(void) { + //add pa/lna config bit setting here + //debug("RX\n"); + hal_io_enable_pa(0); + _delay_us(20); + hal_io_enable_lna(1); + _delay_us(5); + +} + +inline void hal_cc25xx_enter_txmode(void) { + //add pa/lna config bit setting here + //debug("TX\n"); + hal_io_enable_lna(0); + _delay_us(20); + hal_io_enable_pa(1); + _delay_us(5); +} + + +inline void hal_cc25xx_enable_receive(void){ + //switch on rx again + hal_cc25xx_enter_rxmode(); +} + + +inline void hal_cc25xx_read_fifo(uint8_t *buf, uint8_t len){ + hal_cc25xx_register_read_multi(CC25XX_FIFO | READ_FLAG | BURST_FLAG, buf, len); +} + +inline void hal_cc25xx_register_read_multi(uint8_t address, uint8_t *buffer, uint8_t len){ + // select device: + hal_spi_csn_lo(); + + // wait for ready signal + //debug("read_multi address: 0x"); + //debug_put_hex8(address); + //debug(" len: "); + //debug_put_uint8(len); + //debug("\n"); + hal_io_wait_miso_low(); + + // request address (read request) + uint8_t status = hal_spi_tx(address); + + //fill buffer with read commands: + memset(buffer, 0xFF, len); + uint8_t len2 = len; + uint8_t *buffer2 = buffer; + + while(len--){ + *buffer = hal_spi_rx(); + buffer++; + } + +#if DEBUG_PRINT_READ + if (len2 > 0) { + debug("read data len: "); + debug_put_uint8(len2); + debug(" status:"); + debug_put_hex8(status); + debug(" :"); + while(len2--) { + debug(" 0x"); + debug_put_hex8(*buffer2); + buffer2++; + if (len2 % 10 == 0) + debug_flush(); + } + debug("\n"); + } +#endif + + // deselect device + hal_spi_csn_hi(); +} + +inline void hal_cc25xx_register_write_multi(uint8_t address, uint8_t *buffer, uint8_t len){ + //s elect device: + hal_spi_csn_lo(); + + //debug("write "); debug_put_uint8(len); debug_flush(); + // wait for RDY signal: + hal_io_wait_miso_low(); + + //request address (write request) + hal_spi_tx(address | BURST_FLAG); + + // send array + while(len--){ + hal_spi_tx(*buffer); + buffer++; + } + + //deselect device + hal_spi_csn_hi(); +} + +inline void hal_cc25xx_process_packet(volatile uint8_t *packet_received, volatile uint8_t *buffer, uint8_t maxlen){ + if(hal_io_get_gdo() == 1){ + // debug("GDO\n"); + //data received, fetch data + //timeout_set_100us(5); + + *packet_received = 0; + //hal_io_debug(1); + + //there is a bug in the cc2500 + //see p3 http://www.ti.com/lit/er/swrz002e/swrz002e.pdf + //workaround: read len register very quickly twice: + uint8_t len1, len2, len, i; + + //try this 10 times befor giving up: + for (i=0; i<10; i++){ + len1 = hal_cc25xx_get_register_burst(RXBYTES) & 0x7F; + len2 = hal_cc25xx_get_register_burst(RXBYTES) & 0x7F; + if (len1==len2) break; + } + /* + debug("Got len1: "); + debug_put_hex8(len1); + debug(" len2: "); + debug_put_hex8(len2); + debug(" maxlen: "); + debug_put_hex8(maxlen); + debug("\n"); + */ + + //valid len found? + if (len1==len2){ + len = len1; + + //packet received, grab data + uint8_t tmp_buffer[len]; + hal_cc25xx_read_fifo(tmp_buffer, len); + + //only accept valid packet lenbghts: + if (len == maxlen){ + uint8_t i; + for(i=0; i +#include + + +void hal_cc25xx_init(void); +void hal_cc25xx_set_register(uint8_t reg, uint8_t val); +uint8_t hal_cc25xx_get_register(uint8_t address); +void hal_cc25xx_strobe(uint8_t val); + +void hal_cc25xx_enable_receive(void); +void hal_cc25xx_enable_transmit(void); +void hal_cc25xx_enter_rxmode(void); +void hal_cc25xx_enter_txmode(void); + +#define hal_cc25xx_rx_sleep() { delay_us(1352); } +#define hal_cc25xx_tx_sleep() { delay_us(1250); } + +// not used on d4rii +#define hal_cc25xx_disable_rf_interrupt() {} +#define hal_cc25xx_setup_rf_dma(mode) {} +#define hal_cc25xx_partnum_valid(p, v) ((p == 0x80) && (v = 0x03)) + +uint8_t hal_cc25xx_get_status(void); +uint32_t hal_cc25xx_set_antenna(uint8_t id); +void hal_cc25xx_set_gdo_mode(void); +uint8_t hal_cc25xx_get_gdo_status(void); +void hal_cc25xx_process_packet(volatile uint8_t *packet_received, volatile uint8_t *buffer, uint8_t maxlen); +void hal_cc25xx_transmit_packet(volatile uint8_t *buffer, uint8_t len); + +void hal_cc25xx_read_fifo(uint8_t *buf, uint8_t len); +void hal_cc25xx_register_read_multi(uint8_t address, uint8_t *buffer, uint8_t len); +uint8_t hal_cc25xx_transmission_completed(void); + +//adress checks +#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_00 ((0<<1) | (0<<0)) +#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_01 ((0<<1) | (1<<0)) +#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_10 ((1<<1) | (0<<0)) +#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_11 ((1<<1) | (1<<0)) +//append status bytes? +#define CC2500_PKTCTRL1_APPEND_STATUS (1<<2) +//crc autoflush +#define CC2500_PKTCTRL1_CRC_AUTOFLUSH (1<<3) + +// Flags +#define BURST_FLAG 0b01000000 +#define WRITE_FLAG 0b00000000 +#define READ_FLAG 0b10000000 + +//Definitions for burst/single access to registers +#define CC2500_WRITE_SINGLE 0x00 +#define CC2500_WRITE_BURST 0x40 +#define CC2500_READ_SINGLE 0x80 +#define CC2500_READ_BURST 0xC0 + +#define CC2500_STATUS_STATE_IDLE (0<<4) +#define CC2500_STATUS_STATE_RX (1<<4) +#define CC2500_STATUS_STATE_TX (2<<4) +#define CC2500_STATUS_STATE_FSTXON (3<<4) +#define CC2500_STATUS_STATE_CALIBRATE (4<<4) +#define CC2500_STATUS_STATE_SETTLING (5<<4) +#define CC2500_STATUS_STATE_RXFIFO_OVF (6<<4) +#define CC2500_STATUS_STATE_TXFIFO_OVF (7<<4) + +#define hal_cc25xx_get_register_burst(x) hal_cc25xx_get_register(x | READ_FLAG | BURST_FLAG) + + +// strobes +#define RFST_SRES 0x30 +#define RFST_SFSTXON 0x31 +#define RFST_SXOFF 0x32 +#define RFST_SCAL 0x33 +#define RFST_SRX 0x34 +#define RFST_STX 0x35 +#define RFST_SIDLE 0x36 +#define RFST_SWOR 0x38 +#define RFST_SPWD 0x39 +#define RFST_SFRX 0x3A +#define RFST_SFTX 0x3B +#define RFST_SWORRST 0x3C +#define RFST_SNOP 0x3D + +// Status registers +#define PARTNUM 0x30|BURST_FLAG // 0x70 +#define VERSION 0x31|BURST_FLAG // 0x71 +#define FREQEST 0x32|BURST_FLAG // 0x72 +#define LQI 0x33|BURST_FLAG // 0x73 +#define RSSI 0x34|BURST_FLAG // 0x74 +#define MARCSTATE 0x35|BURST_FLAG // 0x75 +#define WORTIME1 0x36|BURST_FLAG // 0x76 +#define WORTIME0 0x37|BURST_FLAG // 0x77 +#define PKTSTATUS 0x38|BURST_FLAG // 0x78 +#define VCO_VC_DAC 0x39|BURST_FLAG // 0x79 +#define TXBYTES 0x3A|BURST_FLAG // 0x7A +#define RXBYTES 0x3B|BURST_FLAG // 0x7B +#define RCCTRL1_STATUS 0x3C|BURST_FLAG // 0x7C +#define RCCTRL0_STATUS 0x3D|BURST_FLAG // 0x7D + +// Status byte states +#define STB_IDLE 0x00 +#define STB_RX 0x10 +#define STB_TX 0x20 +#define STB_FSTXON 0x30 +#define STB_CALIBRATE 0x40 +#define STB_SETTLING 0x50 +#define STB_RX_OVF 0x60 +#define STB_TX_UNDF 0x70 + +// Config registers addresses +#define IOCFG2 0x00 +#define IOCFG1 0x01 +#define IOCFG0 0x02 +#define FIFOTHR 0x03 +#define SYNC1 0x04 +#define SYNC0 0x05 +#define PKTLEN 0x06 +#define PKTCTRL1 0x07 +#define PKTCTRL0 0x08 +#define ADDR 0x09 +#define CHANNR 0x0A +#define FSCTRL1 0x0B +#define FSCTRL0 0x0C +#define FREQ2 0x0D +#define FREQ1 0x0E +#define FREQ0 0x0F +#define MDMCFG4 0x10 +#define MDMCFG3 0x11 +#define MDMCFG2 0x12 +#define MDMCFG1 0x13 +#define MDMCFG0 0x14 +#define DEVIATN 0x15 +#define MCSM2 0x16 +#define MCSM1 0x17 +#define MCSM0 0x18 +#define FOCCFG 0x19 +#define BSCFG 0x1A +#define AGCCTRL2 0x1B +#define AGCCTRL1 0x1C +#define AGCCTRL0 0x1D +#define WOREVT1 0x1E +#define WOREVT0 0x1F +#define WORCTRL 0x20 +#define FREND1 0x21 +#define FREND0 0x22 +#define FSCAL3 0x23 +#define FSCAL2 0x24 +#define FSCAL1 0x25 +#define FSCAL0 0x26 +#define RCCTRL1 0x27 +#define RCCTRL0 0x28 +#define FSTEST 0x29 +#define PTEST 0x2A +#define AGCTEST 0x2B +#define TEST2 0x2C +#define TEST1 0x2D +#define TEST0 0x2E + +#define PA_TABLE0 0x3E + +// FIFO +#define CC25XX_FIFO 0x3F + + +#endif // __HAL_CC25XX_H__ + diff --git a/arch/atmega328/hal_clocksource.c b/arch/atmega328/hal_clocksource.c new file mode 100644 index 0000000..d7cb03f --- /dev/null +++ b/arch/atmega328/hal_clocksource.c @@ -0,0 +1,17 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + diff --git a/arch/atmega328/hal_clocksource.h b/arch/atmega328/hal_clocksource.h new file mode 100644 index 0000000..b23dc97 --- /dev/null +++ b/arch/atmega328/hal_clocksource.h @@ -0,0 +1,7 @@ +#ifndef __HAL_CLOCKSOURCE_H__ +#define __HAL_CLOCKSOURCE_H__ + +//no necessary for stm32, it is done in system startup +#define hal_clocksource_init() {} + +#endif // __HAL_CLOCKSOURCE_H__ diff --git a/arch/atmega328/hal_debug.h b/arch/atmega328/hal_debug.h new file mode 100644 index 0000000..e45960b --- /dev/null +++ b/arch/atmega328/hal_debug.h @@ -0,0 +1,44 @@ +/* + Copyright 2017 fishpepper gmail.com + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com +*/ + +#ifndef HAL_DEBUG_H_ +#define HAL_DEBUG_H_ + +#include "hal_cc25xx.h" +#include "hal_uart.h" +#include + +#define hal_debug_init() hal_uart_init() +#define hal_debug_start_transmission(ch) hal_uart_start_transmission(ch) + + +#define hal_debug_int_enabled() (0) + +#define hal_debug_int_enable() {} +#define hal_debug_int_disable() {} + +#define DEBUG_ISR(void) hal_uart_interrupt(void) +#define HAL_DEBUG_ISR_FLAG_SET() (1) +#define HAL_DEBUG_ISR_CLEAR_FLAG() {} +#define HAL_DEBUG_ISR_DISABLE() {} +#define HAL_DEBUG_TX_DATA(data) hal_uart_tx_data(data) + + + +#endif // HAL_DEBUG_H_ diff --git a/arch/atmega328/hal_defines.h b/arch/atmega328/hal_defines.h new file mode 100644 index 0000000..a2cff0f --- /dev/null +++ b/arch/atmega328/hal_defines.h @@ -0,0 +1,11 @@ +#ifndef __HAL_DEFINES_H__ +#define __HAL_DEFINES_H__ + +#define EXTERNAL_MEMORY +#define EXTERNAL_DATA + +#define LO(w) (w & 0xFF) +#define HI(w) ((w>>8) & 0xFF) +#define __IO + +#endif // __HAL_DEFINES_H__ diff --git a/arch/atmega328/hal_delay.h b/arch/atmega328/hal_delay.h new file mode 100644 index 0000000..c95979b --- /dev/null +++ b/arch/atmega328/hal_delay.h @@ -0,0 +1,9 @@ +#ifndef __HAL_DELAY_H__ +#define __HAL_DELAY_H__ +#include "hal_timeout.h" +#include + +#define hal_delay_ms(ms) _delay_ms(ms); +#define hal_delay_us(us) _delay_us(us); + +#endif // __HAL_DELAY_H__ diff --git a/arch/atmega328/hal_dma.h b/arch/atmega328/hal_dma.h new file mode 100644 index 0000000..e69de29 diff --git a/arch/atmega328/hal_io.c b/arch/atmega328/hal_io.c new file mode 100644 index 0000000..bf333d1 --- /dev/null +++ b/arch/atmega328/hal_io.c @@ -0,0 +1,89 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include +#include "hal_io.h" +#include "config.h" +#include "delay.h" +#include +#include + +void hal_io_init(void) { + /* Set MOSI and SCK output, all others input */ + DDRB = (1< + +void hal_io_init(void); +uint8_t hal_io_bind_request(void); + +void hal_io_wait_miso_low(); +uint8_t hal_io_get_gdo(); +void hal_io_enable_pa(uint8_t enable); +void hal_io_enable_lna(uint8_t enable); +void hal_io_debug(uint8_t enable); +void hal_io_debug2(uint8_t enable); +void hal_io_set_ppm(uint8_t enable); + +#endif // __HAL_IO_H__ diff --git a/arch/atmega328/hal_led.h b/arch/atmega328/hal_led.h new file mode 100644 index 0000000..82cf03b --- /dev/null +++ b/arch/atmega328/hal_led.h @@ -0,0 +1,20 @@ +#ifndef __HAL_LED__H_ +#define __HAL_LED__H_ +#include "config.h" +#include +#include + +void hal_led_init(uint16_t pin); + +#define hal_led_green_init() { } +#define hal_led_green_on() { PORTC |= GREEN_LED_PIN; } +#define hal_led_green_off() { PORTC &= ~ GREEN_LED_PIN; } +#define hal_led_green_toggle() { PORTC ^= GREEN_LED_PIN; } + +#define hal_led_red_init() { } +#define hal_led_red_on() { PORTC |= RED_LED_PIN; } +#define hal_led_red_off() { PORTC &= ~ RED_LED_PIN; } +#define hal_led_red_toggle() { PORTC ^= RED_LED_PIN; } + +#endif //__HAL_LED__H_ + diff --git a/arch/atmega328/hal_ppm.c b/arch/atmega328/hal_ppm.c new file mode 100644 index 0000000..f9a91a9 --- /dev/null +++ b/arch/atmega328/hal_ppm.c @@ -0,0 +1,98 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include + +#include "hal_ppm.h" +#include "hal_io.h" +#include "ppm.h" +#include +#include + +/* + * CS12 CS11 CS10 Description + * 0 0 0 No clock source (Timer/Counter stopped). + * 0 1 clkI/O/1 + * 0 1 0 clkI/O/8 + * 0 1 1 clkI/O/64 + * 1 0 0 clkI/O/256 + * 1 0 1 clkI/O/1024 + */ + +void hal_ppm_init(void) { + cli(); // Disable interrupts + //initialise timer 1: + //we use COMPA and COMPB + //COMPA triggers the io pin level change + //COMPB triggers an interrupt and reloads the data whereas + // Set timer to Mode 15, Fast PWM, TOP: OCR1A, OCR1x at BOTTOM, TOV1 flag on TOP + TCCR1A = (0< divide by 1.5 (=*2/3) to get us +#define HAL_PPM_FRSKY_TO_TICKCOUNT(_frsky) HAL_PPM_US_TO_TICKCOUNT((_frsky)*2/3) + +#define PPM_TIMER_ISR(void) ppm_timer_isr() + +#define HAL_PPM_UPDATE_CCVALUE(x) hal_ppm_update_ccvalue(x) +#define HAL_PPM_ISR_DISABLE() { } +#define HAL_PPM_ISR_ENABLE() { } +#define HAL_PPM_ISR_FLAG_SET() ( 1 ) +#define HAL_PPM_ISR_CLEAR_FLAG() { } + + +#endif // __HAL_PPM_H__ diff --git a/arch/atmega328/hal_sbus.h b/arch/atmega328/hal_sbus.h new file mode 100644 index 0000000..7cf924b --- /dev/null +++ b/arch/atmega328/hal_sbus.h @@ -0,0 +1,11 @@ +#ifndef __HAL_SBUS_H__ +#define __HAL_SBUS_H__ +#include +#include "hal_defines.h" + +void SBUS_USART_IRQHANDLER(void); + +//not used here +#define HAL_SBUS_PREPARE_DATA(a) (a) + +#endif // __HAL_SBUS_H__ diff --git a/arch/atmega328/hal_soft_serial.c b/arch/atmega328/hal_soft_serial.c new file mode 100644 index 0000000..0efced1 --- /dev/null +++ b/arch/atmega328/hal_soft_serial.c @@ -0,0 +1,20 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +void hal_soft_serial_init(void) { +} + diff --git a/arch/atmega328/hal_soft_serial.h b/arch/atmega328/hal_soft_serial.h new file mode 100644 index 0000000..88cbb6b --- /dev/null +++ b/arch/atmega328/hal_soft_serial.h @@ -0,0 +1,25 @@ +#ifndef __HAL_SOFT_SERIAL_H__ +#define __HAL_SOFT_SERIAL_H__ +#include "soft_serial.h" +#include "config.h" + +void hal_soft_serial_init(void); + + +#define HAL_SOFT_SERIAL_PIN_LO() ( 0 ) +#define HAL_SOFT_SERIAL_PIN_HI() ( 1) + + +#define HAL_SOFT_SERIAL_IC_ISR_DISABLE() { } +#define HAL_SOFT_SERIAL_IC_ISR_ENABLE() { } +#define HAL_SOFT_SERIAL_IC_ISR_FLAG_SET() ( 1 ) +#define HAL_SOFT_SERIAL_IC_ISR_FLAG_CLEAR() { } + +#define HAL_SOFT_SERIAL_UP_ISR_DISABLE() { } +#define HAL_SOFT_SERIAL_UP_ISR_ENABLE() { } +#define HAL_SOFT_SERIAL_UP_ISR_FLAG_SET() ( 0 ) +#define HAL_SOFT_SERIAL_UP_ISR_FLAG_CLEAR() { } + +#define HAL_SOFT_SERIAL_UPDATE_TOP_VALUE(x) { } + +#endif // __HAL_SOFT_SERIAL_H__ diff --git a/src/spi.h b/arch/atmega328/hal_soft_spi.c similarity index 72% rename from src/spi.h rename to arch/atmega328/hal_soft_spi.c index fa100f7..8f78f2b 100644 --- a/src/spi.h +++ b/arch/atmega328/hal_soft_spi.c @@ -1,6 +1,4 @@ /* - Copyright 2017 fishpepper gmail.com - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -12,14 +10,14 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . - author: fishpepper gmail.com + author: fishpepper gmail.com, jimmyw github */ -#ifndef SPI_H_ -#define SPI_H_ +#include "hal_soft_spi.h" + +void hal_soft_spi_init(void) { -void spi_init(void); +} -#endif // SPI_H_ diff --git a/arch/atmega328/hal_soft_spi.h b/arch/atmega328/hal_soft_spi.h new file mode 100644 index 0000000..e835192 --- /dev/null +++ b/arch/atmega328/hal_soft_spi.h @@ -0,0 +1,15 @@ +#ifndef __HAL_SOFT_SPI__ +#define __HAL_SOFT_SPI__ +#include +#include "config.h" +#include "main.h" + +void hal_soft_spi_init(void); + +#define SOFT_SPI_CLOCK_HI() { } +#define SOFT_SPI_CLOCK_LO() { } +#define SOFT_SPI_MOSI_HI() { } +#define SOFT_SPI_MOSI_LO() { } + + +#endif diff --git a/arch/atmega328/hal_spi.c b/arch/atmega328/hal_spi.c new file mode 100644 index 0000000..df01ffd --- /dev/null +++ b/arch/atmega328/hal_spi.c @@ -0,0 +1,73 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_spi.h" +#include +#include + +/* SPCR + * SPI2X SPR01 SPR00 DESCRIPTION + * 0 0 0 Clock / 4 + * 0 0 1 Clock / 16 + * 0 1 0 Clock / 64 + * 0 1 1 Clock / 128 + * 1 0 0 Clock / 2 + * 1 0 0 Clock / 8 + * 1 0 1 Clock / 32 + * 1 1 1 Clock / 64 + * + * SPE: Enable + * MSTR: Master + */ + +/* Note, by some reason telemetry fails if divider is higher the 4 */ + +void hal_spi_init(void) { + + /* Enable SPI, Master, set clock rate fck/4 */ + SPCR = (1< +#include "config.h" + +void hal_spi_init(void); + +uint8_t hal_spi_tx(uint8_t address); +uint8_t hal_spi_rx(void); +uint8_t hal_spi_read_address(uint8_t address); +void hal_spi_csn_lo(); +void hal_spi_csn_hi(); + +#endif // __HAL_SPI__H_ + diff --git a/arch/atmega328/hal_storage.c b/arch/atmega328/hal_storage.c new file mode 100644 index 0000000..f2c558c --- /dev/null +++ b/arch/atmega328/hal_storage.c @@ -0,0 +1,31 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_storage.h" +#include "storage.h" +#include + +uint8_t storage_memory[sizeof(STORAGE_DESC)] EEMEM; + +void hal_storage_write(uint8_t *buffer, uint16_t len) { + eeprom_write_block(buffer, storage_memory, len); +} + +void hal_storage_read(uint8_t *storage_ptr, uint16_t len) { + eeprom_read_block(storage_ptr, storage_memory, len); +} + diff --git a/arch/atmega328/hal_storage.h b/arch/atmega328/hal_storage.h new file mode 100644 index 0000000..e976d35 --- /dev/null +++ b/arch/atmega328/hal_storage.h @@ -0,0 +1,13 @@ +#ifndef __HAL_STORAGE__H_ +#define __HAL_STORAGE__H_ +#include + +void hal_storage_write(uint8_t *buffer, uint16_t len); +void hal_storage_read(uint8_t *storage_ptr, uint16_t len); + +#define hal_storage_init() { } +#define hal_storage_wp_enable() { } +#define hal_storage_wp_disable() { } + + +#endif // __HAL_STORAGE__H_ diff --git a/arch/atmega328/hal_timeout.c b/arch/atmega328/hal_timeout.c new file mode 100644 index 0000000..493d614 --- /dev/null +++ b/arch/atmega328/hal_timeout.c @@ -0,0 +1,214 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_timeout.h" +#include "hal_delay.h" + +#include "../../src/debug.h" +#include +#include + +// Took me about 2 days to figure out that it was important that +// these variables was volatile. doh. +static volatile uint32_t timer_1 = 0; +static volatile uint32_t timer_2 = 0; + +/* TIMER0 TCCR0B + * CS02 CS01 CS00 DESCRIPTION + * 0 0 0 Timer/Counter2 Disabled + * 0 0 1 No Prescaling + * 0 1 0 Clock / 8 + * 0 1 1 Clock / 64 + * 1 0 0 Clock / 256 + * 1 0 1 Clock / 1024 + */ + +/* TIMER2 TCCR2B + * CS22 CS21 CS20 DESCRIPTION + * 0 0 0 Timer/Counter2 Disabled + * 0 0 1 No Prescaling + * 0 1 0 Clock / 8 + * 0 1 1 Clock / 32 + * 1 0 0 Clock / 64 + * 1 0 1 Clock / 128 + * 1 1 0 Clock / 256 + * 1 1 1 Clock / 1024 + */ + +void hal_timeout_init(void) { + cli(); // Disable interrupts + + // setup timer1 to use timer 0 + TCCR0A = (1< 0){ + } + PORTD |= (1 << PD4); + hal_timeout_set(10); // 10ms + PORTD &= ~ (1 << PD4); + while(timer_1 > 0){ + } + PORTD |= (1 << PD4); + } +#endif +#ifdef TIMER_TEST2 + debug("timer test_2\n"); + DDRD = (1< 0){ + } + PORTD |= (1 << PD4); + hal_timeout2_set_100us(100); // 10ms + PORTD &= ~ (1 << PD4); + while(timer_2 > 0){ + } + PORTD |= (1 << PD4); + } +#endif +} + +ISR(TIMER0_COMPA_vect){ +#ifdef TIMER_TEST1 + static volatile int c = 0; + if (c) { + PORTD &= ~ (1 << PD5); + c = 0; + } else { + PORTD |= (1 << PD5); + c = 1; + } +#endif + + // Disable interrupt. + if (timer_1 == 0) { + //debug("timeout1\n"); + TIMSK0 &= ~(1 << OCIE0A); + return; + } + timer_1--; +} + +ISR(TIMER2_COMPA_vect){ +#ifdef TIMER_TEST2 + static volatile int c = 0; + if (c) { + PORTD &= ~ (1 << PD5); + c = 0; + } else { + PORTD |= (1 << PD5); + c = 1; + } +#endif + + // Disable interrupt. + if (timer_2 == 0) { + //debug("timeout2\n"); + TIMSK2 &= ~(1 << OCIE2A); + return; + } + timer_2--; +} + + +void hal_timeout_set(__IO uint32_t ms) { + //debug("timeout1 set "); debug_put_hex32(ms); debug_put_newline(); + + //disable OVF interrupts: + TIMSK0 &= ~(1 << OCIE0A); + + //clear counter + TCNT0 = 0; + + //clear pending ints + TIFR0 |= (1< +#include "hal_defines.h" + +void hal_timeout_init(void); +void hal_timeout_set(__IO uint32_t ms); +uint8_t hal_timeout_timed_out(void); + +void hal_timeout2_set_100us(__IO uint32_t hus); +uint8_t hal_timeout2_timed_out(void); + + +#endif // __HAL_TIMEOUT__H_ diff --git a/arch/atmega328/hal_uart.c b/arch/atmega328/hal_uart.c new file mode 100644 index 0000000..2e07ba7 --- /dev/null +++ b/arch/atmega328/hal_uart.c @@ -0,0 +1,80 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_uart.h" +#include +#include +#include "config.h" + +#define BAUD_PRESCALE (F_CPU / 4 / USART_BAUDRATE - 1) / 2 + +// &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR +// &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0 + +volatile uint8_t hal_usart_txe_is_on; + +ISR(USART_UDRE_vect) +{ + // Disable this interrupt + UCSR0B &= ~(1<> 8; + UBRR0L = BAUD_PRESCALE; + UCSR0B |= (1< +#include +#include + +void hal_uart_init(void); +void hal_uart_start_transmission(uint8_t ch); +void hal_uart_tx_data(uint8_t ch); + +uint8_t hal_uart_int_enabled(void); +void hal_uart_interrupt(void); + + +#define DEBUG_ISR(void) hal_uart_interrupt(void) +#define HAL_UART_ISR_FLAG_SET() (1) +#define HAL_UART_ISR_CLEAR_FLAG() {} +#define HAL_UART_ISR_DISABLE() {} +#define HAL_UART_TX_DATA(data) hal_uart_tx_data(data) + + +#endif // __HAL_UART__H_ diff --git a/arch/atmega328/hal_wdt.c b/arch/atmega328/hal_wdt.c new file mode 100644 index 0000000..c2f2b42 --- /dev/null +++ b/arch/atmega328/hal_wdt.c @@ -0,0 +1,27 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "hal_wdt.h" + +void hal_wdt_init(void) { + +} + +void hal_wdt_reset(void) { + +} + diff --git a/arch/atmega328/hal_wdt.h b/arch/atmega328/hal_wdt.h new file mode 100644 index 0000000..9e0a60a --- /dev/null +++ b/arch/atmega328/hal_wdt.h @@ -0,0 +1,7 @@ +#ifndef __HAL_WDT_H__ +#define __HAL_WDT_H__ + +void hal_wdt_init(void); +void hal_wdt_reset(void); + +#endif // __HAL_WDT_H__ \ No newline at end of file diff --git a/board/arduino/README.md b/board/arduino/README.md new file mode 100644 index 0000000..e5bc1a1 --- /dev/null +++ b/board/arduino/README.md @@ -0,0 +1,41 @@ +# Arduino target + +This target is tested on a Ardunio Pro Mini, but the arch will work on any board that runs Atmel Mega 328P if you clone and update the board specification. +My goal is to support an open firmware for all the microquads around. + +Remember to run the arduino on 3.3 volts, as the CC2500 chip will die on 5V, mine also have a 8Mhz crystal as 16Mhz is considered unstable for 3.3 volt use. + +You need to connect a CC2500 chip using SPI. + +This version is using the hardware SPI implementation of the Arduino, now Software SPI is currently available so SPI can not be remapped for the moment. + +Also there is no SBUS support, please feel free to help. + +Here is how to build and flash: +``` +make TARGET=arduino TOOLROOT=/path/to/toolchain BOARD_SPEED=8000000 V=1 SERIAL_PORT=/dev/tty.SLAB_USBtoUART SERIAL_SPEED=57600 clean flash +``` + +You will se debug serial output on the uart0 at 115200bps. + +## Pin-Mapping CC2500: + +``` +D2 GDO2 +D6 PA-Enable (For boards with output amplifier) +D7 LNA-Enable (For board with input amplifier) +D10 CSN +D11 MOSI +D12 MISO +D13 SCK +``` + +## Other: + +``` +D9 PPM out +D3 Bind (input), Put positive to enter bind mode +A1 Green led +A2 Red led +``` + diff --git a/board/arduino/arduino_pins.h b/board/arduino/arduino_pins.h new file mode 100644 index 0000000..d347224 --- /dev/null +++ b/board/arduino/arduino_pins.h @@ -0,0 +1,65 @@ +/* Map arduino pin names to atmega ports */ + +#define A0_PIN DDC0 +#define A1_PIN DDC1 +#define A2_PIN DDC2 +#define A3_PIN DDC3 +#define A4_PIN DDC4 +#define A5_PIN DDC5 +#define A0_PORT PORTC +#define A1_PORT PORTC +#define A2_PORT PORTC +#define A3_PORT PORTC +#define A4_PORT PORTC +#define A5_PORT PORTC +#define A0_INP PINC +#define A1_INP PINC +#define A2_INP PINC +#define A3_INP PINC +#define A4_INP PINC +#define A5_INP PINC + +#define RXI_PIN DDD0 +#define TX0_PIN DDD1 +#define D2_PIN DDD2 +#define D3_PIN DDD3 +#define D4_PIN DDD4 +#define D5_PIN DDD5 +#define D6_PIN DDD6 +#define D7_PIN DDD7 +#define RXI_PORT PORTD +#define TX0_PORT PORTD +#define D2_PORT PORTD +#define D3_PORT PORTD +#define D4_PORT PORTD +#define D5_PORT PORTD +#define D6_PORT PORTD +#define D7_PORT PORTD +#define RXI_INP PIND +#define TX0_INP PIND +#define D2_INP PIND +#define D3_INP PIND +#define D4_INP PIND +#define D5_INP PIND +#define D6_INP PIND +#define D7_INP PIND + +#define D8_PIN DDB0 +#define D9_PIN DDB1 +#define D10_PIN DDB2 +#define MOSI_PIN DDB3 +#define MISO_PIN DDB4 +#define SCK_PIN DDB5 +#define D8_PORT PORTB +#define D9_PORT PORTB +#define D10_PORT PORTB +#define MOSI_PORT PORTB +#define MISO_PORT PORTB +#define SCK_PORT PORTB +#define D8_INP PINB +#define D9_INP PINB +#define D10_INP PINB +#define MOSI_INP PINB +#define MISO_INP PINB +#define SCK_INP PINB + diff --git a/board/arduino/config.h b/board/arduino/config.h new file mode 100644 index 0000000..027a991 --- /dev/null +++ b/board/arduino/config.h @@ -0,0 +1,56 @@ +/* + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + author: fishpepper gmail.com, jimmyw github +*/ + +#include "arduino_pins.h" + +#define USART_BAUDRATE 115200 +#define DEFAULT_FSCAL_VALUE -69 + + +/* MAP Arduino pins to functions */ + + +#define DD_MOSI_PIN MOSI_PIN // PIN11 +#define DD_MOSI_PORT MOSI_PORT +#define DD_MISO_PIN MISO_PIN // PIN12 +#define DD_MISO_INP MISO_INP +#define DD_SCK_PIN SCK_PIN // PIN13 +#define DD_SCK_PORT SCK_PORT +#define DD_SS_PIN D10_PIN +#define DD_SS_PORT D10_PORT + +#define DD_GDO_PIN D2_PIN +#define DD_GDO_INP D2_INP + +#define BIND_PIN D3_PIN +#define BIND_INP D3_INP +#define DEBUG_PIN D4_PIN +#define DEBUG_PORT D4_PORT +#define DEBUG2_PIN D5_PIN +#define DEBUG2_PORT D5_PORT +#define PA_EN_PIN D6_PIN +#define PA_EN_PORT D6_PORT +#define LNA_EN_PIN D7_PIN +#define LNA_EN_PORT D7_PORT +#define PPM_PIN D9_PIN +#define PPM_PORT D9_PORT + +#define GREEN_LED_PIN A1_PIN +#define GREEN_LED_PORT A1_PORT +#define RED_LED_PIN A2_PIN +#define RED_LED_PORT A2_PORT + diff --git a/board/arduino/target.mk b/board/arduino/target.mk new file mode 100644 index 0000000..89fe36a --- /dev/null +++ b/board/arduino/target.mk @@ -0,0 +1,14 @@ + + +# Compilation Flags +BOARD_NAME?=atmega328p +BOARD_SPEED?=16000000 +BOARD_FLAGS?= -mmcu=$(BOARD_NAME) -DF_CPU=$(BOARD_SPEED)L +SERIAL_PORT?=/dev/tty.usbserial-A50285BI +SERIAL_SPEED?=56700 + +# continue with normal atmega build +ARCH_DIR = arch/atmega328 +ARCH_MAKEFILE = $(ARCH_DIR)/atmega328.mk + +