From 404b55c87f881fa6dce93eb6185abf6c9610c4be Mon Sep 17 00:00:00 2001 From: bsongis Date: Tue, 9 Dec 2014 18:57:43 +0100 Subject: [PATCH] MEGA2560 update (all commits merged in only one) --- radio/src/Makefile | 15 +- radio/src/opentx.cpp | 6 +- radio/src/pulses/pulses_avr.cpp | 20 +- radio/src/targets/mega2560/00readme.txt | 21 +- radio/src/targets/mega2560/board_mega2560.cpp | 4 +- radio/src/targets/mega2560/board_mega2560.h | 188 +++++++++--------- radio/src/targets/mega2560/io_mega2560.h | 160 --------------- radio/src/targets/mega2560/rtc_driver.cpp | 95 --------- 8 files changed, 123 insertions(+), 386 deletions(-) delete mode 100644 radio/src/targets/mega2560/io_mega2560.h delete mode 100644 radio/src/targets/mega2560/rtc_driver.cpp diff --git a/radio/src/Makefile b/radio/src/Makefile index 92f032fef..6df2794a2 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -588,6 +588,7 @@ ifeq ($(PCB), MEGA2560) OPT = s CPPDEFS = -DF_CPU=$(F_CPU)UL -DPCBMEGA2560 -DCPUM2560 -DEEPROM_VARIANT=0 -DAUDIO -DRTCLOCK SDCARD = YES + BUZZER = YES THR_TRACE = YES INCDIRS += targets/mega2560 targets/stock FatFs FatFs/option BOARDSRC = main_avr.cpp targets/mega2560/board_mega2560.cpp @@ -600,10 +601,20 @@ ifeq ($(PCB), MEGA2560) ifeq ($(SDCARD), YES) EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c targets/gruvin9x/diskio.cpp CPPDEFS += -DRTCLOCK - CPPSRC += rtc.cpp targets/mega2560/rtc_driver.cpp + CPPSRC += rtc.cpp targets/gruvin9x/rtc_driver.cpp + endif + + ifeq ($(BUZZER), YES) + CPPDEFS += -DBUZZER + CPPSRC += buzzer.cpp + endif + + ifeq ($(VOICE), YES) + CPPDEFS += -DVOICE + CPPSRC += targets/gruvin9x/somo14d.cpp endif - # Enable extra rotary encoders (Gruvin9x board only) + # Enable extra rotary encoders # Values = YES, NO ROTARY_ENCODERS = 2 CPPDEFS += -DROTARY_ENCODERS=${ROTARY_ENCODERS} diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 77a4ece71..bd07fcc74 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1513,7 +1513,7 @@ void getADC() #if !defined(CPUARM) void getADC_bandgap() { -#if defined(CPUM2560) +#if defined(PCBGRUVIN9X) static uint8_t s_bgCheck = 0; static uint16_t s_bgSum = 0; ADCSRA|=0x40; // request sample @@ -1527,6 +1527,8 @@ void getADC_bandgap() s_bgSum += ADC; } ADCSRB |= (1<> 5 ; if (Current_analogue > Current_max) Current_max = Current_analogue ; -#elif defined(CPUM2560) && !defined(SIMU) +#elif defined(PCBGRUVIN9X) && !defined(SIMU) // For PCB V4, use our own 1.2V, external reference (connected to ADC3) ADCSRB &= ~(1<>1) | 0x80; //shift in stop bit } -#if defined (PCBGRUVIN9X) +#if defined (CPUM2560) _send_1(len+BITLEN_DSM2+3); // 2 stop bits #else _send_1(len+BITLEN_DSM2-1); // 2 stop bits @@ -568,7 +568,7 @@ void setupPulsesDSM2() pulses2MHzWPtr -= 1; //remove last stopbits and -#if !defined(PCBGRUVIN9X) +#if !defined(CPUM2560) //G: Removed to get waveform correct on analyser. Leave in for stock board until tests can be done. _send_1(255); // prolong them #endif @@ -757,7 +757,7 @@ void setupPulses() if (s_pulses_paused) required_protocol = PROTO_NONE; -#if defined(PCBGRUVIN9X) && defined(DSM2_PPM) && defined(TX_CADDY) +#if defined(CPUM2560) && defined(DSM2_PPM) && defined(TX_CADDY) // This should be here, executed on every loop, to ensure re-setting of the // TX moudle power control output register, in case of electrical glitch. // (Following advice of Atmel for MCU's used in industrial / mission cricital @@ -911,7 +911,7 @@ void setupPulses() sei(); #endif setupPulsesDSM2(); // Different versions for DSM2=SERIAL vs. DSM2=PPM -#if defined(PCBGRUVIN9X) && defined(DSM2_PPM) +#if defined(CPUM2560) && defined(DSM2_PPM) // Ensure each DSM2=PPM serial packet starts out with the correct bit polarity TCCR1A = (0 << WGM10) | (3< - * - Andreas Weitl - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Gabriel Birkus - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * opentx is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - * - */ - -#ifndef _HAL_ -#define _HAL_ - -/* - * GPIOS - */ - -// Keys -#define GPIO_BUTTON_MENU GPIOL->IDR // only one port : to simplify ? // -#define GPIO_BUTTON_EXIT GPIOL->IDR -#define GPIO_BUTTON_RIGHT GPIOL->IDR -#define GPIO_BUTTON_LEFT GPIOL->IDR -#define GPIO_BUTTON_UP GPIOL->IDR -#define GPIO_BUTTON_DOWN GPIOL->IDR -#define PIN_BUTTON_MENU GPIO_Pin_4 -#define PIN_BUTTON_EXIT GPIO_Pin_5 -#define PIN_BUTTON_RIGHT GPIO_Pin_2 -#define PIN_BUTTON_LEFT GPIO_Pin_3 -#define PIN_BUTTON_UP GPIO_Pin_1 -#define PIN_BUTTON_DOWN GPIO_Pin_0 - -// Trims -#define GPIO_TRIM_LH_L GPIOK->IDR // only one port : to simplify ? // -#define GPIO_TRIM_LH_R GPIOK->IDR -#define GPIO_TRIM_LV_DN GPIOK->IDR -#define GPIO_TRIM_LV_UP GPIOK->IDR -#define GPIO_TRIM_RH_L GPIOK->IDR -#define GPIO_TRIM_RH_R GPIOK->IDR -#define GPIO_TRIM_RV_DN GPIOK->IDR -#define GPIO_TRIM_RV_UP GPIOK->IDR -#define PIN_TRIM_LH_L GPIO_Pin_0 -#define PIN_TRIM_LH_R GPIO_Pin_1 -#define PIN_TRIM_LV_DN GPIO_Pin_2 -#define PIN_TRIM_LV_UP GPIO_Pin_3 -#define PIN_TRIM_RH_L GPIO_Pin_4 -#define PIN_TRIM_RH_R GPIO_Pin_5 -#define PIN_TRIM_RV_DN GPIO_Pin_5 -#define PIN_TRIM_RV_UP GPIO_Pin_6 - -// Switchs -#define GPIO_PIN_SW_A GPIOC->IDR // A, B, C... to rename to ID1/2... ? // -#define GPIO_PIN_SW_B GPIOC->IDR -#define GPIO_PIN_SW_C GPIOD->IDR -#define GPIO_PIN_SW_D GPIOG->IDR -#define GPIO_PIN_SW_E GPIOG->IDR -#define GPIO_PIN_SW_F GPIOG->IDR -#define GPIO_PIN_SW_G GPIOL->IDR -#define GPIO_PIN_SW_H GPIOL->IDR -#define PIN_SW_A GPIO_Pin_1 -#define PIN_SW_B GPIO_Pin_0 -#define PIN_SW_C GPIO_Pin_7 -#define PIN_SW_D GPIO_Pin_2 -#define PIN_SW_E GPIO_Pin_1 -#define PIN_SW_F GPIO_Pin_0 -#define PIN_SW_G GPIO_Pin_6 -#define PIN_SW_H GPIO_Pin_7 - -// Rotary encoders -#define GPIO_PIN_ROT_ENC_1_A GPIOH->IDR -#define GPIO_PIN_ROT_ENC_1_B GPIOJ->IDR -#define GPIO_PIN_ROT_ENC_1_PUSH GPIOJ->IDR -#define GPIO_PIN_ROT_ENC_2_A GPIOD->IDR -#define GPIO_PIN_ROT_ENC_2_B GPIOD->IDR -#define GPIO_PIN_ROT_ENC_2_PUSH GPIOH->IDR -#define PIN_ROT_ENC_1_A GPIO_Pin_1 -#define PIN_ROT_ENC_1_B GPIO_Pin_0 -#define PIN_ROT_ENC_1_PUSH GPIO_Pin_1 -#define PIN_ROT_ENC_2_A GPIO_Pin_0 -#define PIN_ROT_ENC_2_B GPIO_Pin_3 -#define PIN_ROT_ENC_2_PUSH GPIO_Pin_2 - -// ADC -#define GPIO_PIN_ADC GPIOK->IDR -#define PIN_STK_J1 GPIO_Pin_0 -#define PIN_STK_J2 GPIO_Pin_1 -#define PIN_STK_J3 GPIO_Pin_2 -#define PIN_STK_J4 GPIO_Pin_3 -#define PIN_POT_1 GPIO_Pin_4 -#define PIN_POT_2 GPIO_Pin_5 -#define PIN_POT_3 GPIO_Pin_6 -#define PIN_MVOLT GPIO_Pin_7 - -// Accessories -#define GPIO_PIN_PPM_IN GPIOB->IDR -#define GPIO_PIN_PPM_OUT GPIOB->IDR -#define GPIO_PIN_SIM_CTL GPIOB->IDR -#define GPIO_PIN_TELEM_RX GPIOE->IDR -#define GPIO_PIN_TELEM_TX GPIOE->IDR -#define GPIO_PIN_SPEAKER GPIOE->IDR -#define GPIO_PIN_BUZZER GPIOB->IDR -#define GPIO_PIN_JACK_PRES GPIOH->IDR -#define GPIO_PIN_HOLD_PWR GPIOH->IDR -#define PIN_PPM_IN GPIO_Pin_7 -#define PIN_PPM_OUT GPIO_Pin_6 -#define PIN_SIM_CTL GPIO_Pin_5 -#define PIN_TELEM_RX GPIO_Pin_0 -#define PIN_TELEM_TX GPIO_Pin_1 -#define PIN_SPEAKER GPIO_Pin_3 -#define PIN_BUZZER GPIO_Pin_4 -#define PIN_JACK_PRES GPIO_Pin_5 -#define PIN_HOLD_PWR GPIO_Pin_4 - -// LCD -#define GPIO_LCD_DAT GPIOA->IDR -#define GPIO_LCD_CTRL GPIOC->IDR -#define PIN_LCD_E GPIO_Pin_7 -#define PIN_LCD_RnW GPIO_Pin_6 -#define PIN_LCD_A0 GPIO_Pin_5 -#define PIN_LCD_RES GPIO_Pin_4 -#define PIN_LCD_CS1 GPIO_Pin_3 -#define PIN_LCD_LIGHT GPIO_Pin_2 - -// SD -#define GPIO_SD GPIOB->IDR -#define PIN_SD_MISO GPIO_Pin_3 -#define PIN_SD_MOSI GPIO_Pin_2 -#define PIN_SD_SCK GPIO_Pin_1 -#define PIN_SD_CS GPIO_Pin_0 - #define SD_IS_HC() (0) // ? - #define SD_GET_BLOCKNR() (0) // ? - #define SD_GET_SIZE_MB() (0) // ? - #define SD_GET_SPEED() (0) // ? - -#endif \ No newline at end of file diff --git a/radio/src/targets/mega2560/rtc_driver.cpp b/radio/src/targets/mega2560/rtc_driver.cpp deleted file mode 100644 index 76c4aec49..000000000 --- a/radio/src/targets/mega2560/rtc_driver.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Authors (alphabetical order) - * - Andre Bernet - * - Andreas Weitl - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Gabriel Birkus - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * opentx is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - * - */ - - -/*--------------------------------------------------------------------------*/ -/* RTC controls */ - -#include "../opentx.h" -#include "../FatFs/integer.h" - -typedef struct { - WORD year; /* 2000..2099 */ - BYTE month; /* 1..12 */ - BYTE mday; /* 1.. 31 */ - BYTE wday; /* 1..7 */ - BYTE hour; /* 0..23 */ - BYTE min; /* 0..59 */ - BYTE sec; /* 0..59 */ -} RTC; - -void rtc_gettime(struct gtm * utm) -{ - RTC rtc = {0,0,0,0,0,0,0}; - - // TODO g9x_rtc_gettime(&rtc); - - utm->tm_year = rtc.year - 1900; - utm->tm_mon = rtc.month - 1; - utm->tm_mday = rtc.mday; - utm->tm_hour = rtc.hour; - utm->tm_min = rtc.min; - utm->tm_sec = rtc.sec; - utm->tm_wday = rtc.wday - 1; -} - -void rtcSetTime(struct gtm * t) -{ - g_rtcTime = gmktime(t); // update local timestamp and get wday calculated - g_ms100 = 0; // start of next second begins now - -#if 0 - RTC rtc; - rtc.year = t->tm_year + 1900; - rtc.month = t->tm_mon + 1; - rtc.mday = t->tm_mday; - rtc.hour = t->tm_hour; - rtc.min = t->tm_min; - rtc.sec = t->tm_sec; - rtc.wday = t->tm_wday + 1; - g9x_rtcSetTime(&rtc); -#endif -} - -void rtcInit (void) -{ - // TODO - - struct gtm utm; - rtc_gettime(&utm); - g_rtcTime = gmktime(&utm); -} -