From c00620b89100359b3fbf10d2f9da298a4b62c0b3 Mon Sep 17 00:00:00 2001 From: "f.aguerre@wanadoo.fr" Date: Sat, 16 Mar 2013 19:55:20 +0000 Subject: [PATCH] New MEGA2560 board (DIY transmitter based on Arduino MEGA2560) --- src/Makefile | 38 ++++++- src/mega2560/00readme.txt | 22 ++++ src/mega2560/io_mega2560.h | 160 ++++++++++++++++++++++++++++ src/mega2560/lcd_driver_ST7565R.cpp | 132 +++++++++++++++++++++++ 4 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 src/mega2560/00readme.txt create mode 100644 src/mega2560/io_mega2560.h create mode 100644 src/mega2560/lcd_driver_ST7565R.cpp diff --git a/src/Makefile b/src/Makefile index 3250b9236..c929ca1aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -50,7 +50,7 @@ DELAY = 5 #----------- BUILD OPTIONS --------------------------- # PCB version -# Values: 9X, 9X128, 9XR, 9XR128, GRUVIN9X, SKY9X, X9D +# Values: 9X, 9X128, 9XR, 9XR128, GRUVIN9X, MEGA2560, SKY9X, X9D # Old values STD and STD128 are mapped to 9X and 9X128 for compatibility PCB = 9X @@ -248,6 +248,14 @@ ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128)) endif ifeq ($(PCB), GRUVIN9X) + ARCH = AVR + TRGT = avr- + MCU = atmega2560 + CPPDEFS += -DF_CPU=$(F_CPU)UL + SDCARD = NO +endif + +ifeq ($(PCB), MEGA2560) ARCH = AVR ifeq ($(PCBREV), REV0) CPPDEFS += -DREV0 @@ -627,6 +635,34 @@ ifeq ($(PCB), GRUVIN9X) CPPDEFS += -DROTARY_ENCODERS=${ROTARY_ENCODERS} endif +ifeq ($(PCB), MEGA2560) + # ARDUINO2560 DIY RADIO + OPT = 2 + CPPDEFS += -DPCBGRUVIN9X -DEEPROM_VARIANT=0 -DAUDIO -DHAPTIC + EXTRAINCDIRS += gruvin9x stock FatFs FatFs/option + BOARDSRC += mega2560/board_mega2560.cpp + EXTRABOARDSRC += mega2560/lcd_driver_ST7565R.cpp + EEPROMSRC = eeprom_common.cpp eeprom_rlc.cpp + PULSESSRC = pulses_avr.cpp + CPPSRC += audio_avr.cpp haptic.cpp + + ifeq ($(SDCARD), YES) + CPPDEFS += -DRTCLOCK + CPPSRC += rtc.cpp gruvin9x/rtc_driver.cpp + EXTRABOARDSRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c gruvin9x/diskio.cpp + endif + + ifeq ($(VOICE), YES) + CPPSRC += gruvin9x/somo14d.cpp + CPPDEFS += -DVOICE + endif + + # Enable extra rotary encoders (Gruvin9x board only) + # Values = YES, NO + ROTARY_ENCODERS = 2 + CPPDEFS += -DROTARY_ENCODERS=${ROTARY_ENCODERS} +endif + ifeq ($(PCB), $(filter $(PCB), STD128 9X128 9XR128)) # 9x radio with Atmega 64 replace by Atmega 128 OPT = 2 diff --git a/src/mega2560/00readme.txt b/src/mega2560/00readme.txt new file mode 100644 index 000000000..efa69b427 --- /dev/null +++ b/src/mega2560/00readme.txt @@ -0,0 +1,22 @@ +MEGA2560 board + + +======================= DESCRIPTION ======================= + +DIY radio wih : +- Arduino MEGA2560 or compatible +- Artronic LCD 128x64 ST7565R (and, in a second time : Digole LCD 128x64 ST9720) +- Aurora9 gimballs +- home made wood (or fiberglass) case +- Gruvin9x features (soft-off, SD-Card, etc.) with some pins reassignment + +Drawings (case, additional cards, wiring) and components listing will follow + + +========================= STATUS ========================== +LCD driver ST7565R : works +Pins assignment : done (io_mega2560.h) +Additional cards : + - LCD driver (3.3V + backlight) : works + - PPM + power management : in test + - gimballs Op Amp : in test \ No newline at end of file diff --git a/src/mega2560/io_mega2560.h b/src/mega2560/io_mega2560.h new file mode 100644 index 000000000..0e8b8553d --- /dev/null +++ b/src/mega2560/io_mega2560.h @@ -0,0 +1,160 @@ +/* + * 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 + * + * open9x 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/src/mega2560/lcd_driver_ST7565R.cpp b/src/mega2560/lcd_driver_ST7565R.cpp new file mode 100644 index 000000000..e32ee19ed --- /dev/null +++ b/src/mega2560/lcd_driver_ST7565R.cpp @@ -0,0 +1,132 @@ +/* + * 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 + * + * open9x 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. + * + */ + +#include "open9x.h" + +#define delay_1us() _delay_us(1) +void delay_1_5us(int ms) +{ + for(int i=0; i0; --x) { + PORTA_LCD_DAT = *p++; + PORTC_LCD_CTRL |= (1<