├── OpenGround.creator ├── OpenGround.config ├── stylecheck ├── cpplint_test_header.h └── README ├── .travis.sh ├── linker ├── STM32F072VB_FLASH.ld └── stm32f072.ld ├── pcb ├── custom.bck ├── custom.dcm ├── README.md ├── gerber │ ├── openground_cc2500-B_SilkS.gbo │ ├── openground_cc2500.drl │ ├── openground_cc2500-Edge_Cuts.gbr │ ├── openground_cc2500-B_Mask.gbs │ └── openground_cc2500-F_Mask.gts ├── openground_cc2500.cmp ├── openground_cc2500.pro ├── openground_cc2500.net ├── openground_cc2500.sch └── custom.lib ├── .gitmodules ├── peripheral_lib ├── Release_Notes.html ├── inc │ ├── stm32f0xx_wwdg.h │ ├── stm32f0xx_dbgmcu.h │ ├── stm32f0xx_misc.h │ ├── stm32f0xx_iwdg.h │ └── stm32f0xx_crc.h └── src │ └── stm32f0xx_misc.c ├── src ├── eeprom_emulation │ ├── LICENSE.md │ └── st_eeprom.h ├── macros.h ├── main.h ├── wdt.h ├── crc16.h ├── assert.h ├── delay.h ├── clocksource.h ├── usb.h ├── font.c ├── io.h ├── eeprom.h ├── spi.h ├── debug.h ├── timeout.h ├── sound.h ├── crc16.c ├── font.h ├── wdt.c ├── delay.c ├── telemetry.h ├── led.h ├── assert.c ├── console.h ├── config.c ├── led.c ├── adc.h ├── storage.h ├── fifo.h ├── gui.h ├── clocksource.c ├── timeout.c ├── fonts │ ├── metric3x5.h │ ├── tomthumb3x5.h │ ├── system5x7.h │ ├── metric7x12.h │ └── metric15x26.h ├── lcd.h ├── io.c ├── touch.h ├── console.c ├── screen.h ├── frsky.h ├── config.h ├── fifo.c ├── eeprom.c ├── sound.c ├── main.c ├── storage.c ├── debug.c └── lcd.c ├── README.md ├── .gitignore ├── .travis.yml ├── OpenGround.includes ├── scripts └── generate_hoptable.py └── device ├── system_stm32f0xx.h └── stm32f0xx_conf.h /OpenGround.creator: -------------------------------------------------------------------------------- 1 | [General] 2 | -------------------------------------------------------------------------------- /OpenGround.config: -------------------------------------------------------------------------------- 1 | // ADD PREDEFINED MACROS HERE! 2 | -------------------------------------------------------------------------------- /stylecheck/cpplint_test_header.h: -------------------------------------------------------------------------------- 1 | // A test header for cpplint_unittest.py. 2 | -------------------------------------------------------------------------------- /.travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REVISION=$(git rev-parse --short HEAD) 3 | make clean 4 | make 5 | -------------------------------------------------------------------------------- /linker/STM32F072VB_FLASH.ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fishpepper/OpenGround/HEAD/linker/STM32F072VB_FLASH.ld -------------------------------------------------------------------------------- /pcb/custom.bck: -------------------------------------------------------------------------------- 1 | EESchema-DOCLIB Version 2.0 Date: Wed 05 Oct 2016 01:12:03 PM CEST 2 | # 3 | #End Doc Library 4 | -------------------------------------------------------------------------------- /pcb/custom.dcm: -------------------------------------------------------------------------------- 1 | EESchema-DOCLIB Version 2.0 Date: Wed 05 Oct 2016 01:49:45 PM CEST 2 | # 3 | #End Doc Library 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libopencm3"] 2 | path = libopencm3 3 | url = https://github.com/fishpepper/libopencm3.git 4 | -------------------------------------------------------------------------------- /peripheral_lib/Release_Notes.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fishpepper/OpenGround/HEAD/peripheral_lib/Release_Notes.html -------------------------------------------------------------------------------- /src/eeprom_emulation/LICENSE.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fishpepper/OpenGround/HEAD/src/eeprom_emulation/LICENSE.md -------------------------------------------------------------------------------- /pcb/README.md: -------------------------------------------------------------------------------- 1 | This is a adapter PCB to adapt the cc2500 module to the Flysky PCB pads. 2 | 3 | I shared my OSH-Park project, you can order the boards here: 4 | https://oshpark.com/shared_projects/rbAfYjZf 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGround 2 | 3 | [![Build Status](https://travis-ci.org/fishpepper/OpenGround.svg?branch=master)](https://travis-ci.org/fishpepper/OpenGround) 4 | 5 | 6 | a frsky compatible opensource firmware for the flysky fs-i6s and the turnigy evolution 7 | 8 | for now see my blog for more details [http://fishpepper.de/projects/openground/] 9 | -------------------------------------------------------------------------------- /pcb/gerber/openground_cc2500-B_SilkS.gbo: -------------------------------------------------------------------------------- 1 | G04 (created by PCBNEW (2013-jul-07)-stable) date Mon 10 Oct 2016 08:48:14 PM CEST* 2 | %MOIN*% 3 | G04 Gerber Fmt 3.4, Leading zero omitted, Abs format* 4 | %FSLAX34Y34*% 5 | G01* 6 | G70* 7 | G90* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.00590551*% 10 | G04 APERTURE END LIST* 11 | G54D10* 12 | M02* 13 | -------------------------------------------------------------------------------- /pcb/openground_cc2500.cmp: -------------------------------------------------------------------------------- 1 | Cmp-Mod V01 Created by CvPcb (2013-jul-07)-stable date = Wed 05 Oct 2000 01:17:42 AM CEST 2 | 3 | BeginCmp 4 | TimeStamp = /57F4E071; 5 | Reference = U1; 6 | ValeurCmp = FS-I6S_FOOTPRINT; 7 | IdModule = FS-i6s_footprint; 8 | EndCmp 9 | 10 | BeginCmp 11 | TimeStamp = /57F4E080; 12 | Reference = U2; 13 | ValeurCmp = CC2500_FOOTPRINT; 14 | IdModule = CC2500_footprint; 15 | EndCmp 16 | 17 | EndListe 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | # Object files 3 | *.o 4 | *.d 5 | *.ko 6 | *.user* 7 | *.bin 8 | *.lst 9 | *.obj 10 | *.elf 11 | 12 | # Precompiled Headers 13 | *.gch 14 | *.pch 15 | 16 | # Libraries 17 | *.a 18 | *.la 19 | *.lo 20 | 21 | # Shared objects (inc. Windows DLLs) 22 | *.dll 23 | *.so 24 | *.so.* 25 | *.dylib 26 | 27 | # Executables 28 | *.exe 29 | *.out 30 | *.app 31 | *.i*86 32 | *.x86_64 33 | *.hex 34 | 35 | # Debug files 36 | *.dSYM/ 37 | *.su 38 | src/hoptable.h 39 | -------------------------------------------------------------------------------- /src/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef MACROS_H__ 2 | #define MACROS_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define GPIO_RCC(GPIO) (((0x14) << 5) + (17 + ((GPIO - PERIPH_BASE_AHB2)/0x0400))) 8 | 9 | #define DEFINE_TO_STR(x) #x 10 | #define DEFINE_TO_STR_VAL(x) DEFINE_TO_STR(x) 11 | 12 | #define min(a, b) (((a) < (b)) ? (a):(b)) 13 | #define max(a, b) (((a) > (b)) ? (a):(b)) 14 | 15 | #ifdef UNUSED 16 | #elif defined(__GNUC__) 17 | # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) 18 | #elif defined(__LCLINT__) 19 | # define UNUSED(x) /*@unused@*/ x 20 | #else 21 | # define UNUSED(x) x 22 | #endif 23 | 24 | #endif // MACROS_H__ 25 | -------------------------------------------------------------------------------- /pcb/gerber/openground_cc2500.drl: -------------------------------------------------------------------------------- 1 | M48 2 | INCH,TZ 3 | T1C0.031 4 | T2C0.047 5 | % 6 | G90 7 | G05 8 | T1 9 | X37150Y-26250 10 | X37150Y-28350 11 | X37250Y-29900 12 | X37300Y-24900 13 | X38200Y-24550 14 | X38550Y-27100 15 | X39100Y-26050 16 | X39644Y-22094 17 | X40700Y-28600 18 | X41950Y-18200 19 | X42750Y-18300 20 | X42750Y-19150 21 | T2 22 | X34721Y-21059 23 | X34721Y-22043 24 | X34721Y-23027 25 | X34721Y-24799 26 | X34721Y-25980 27 | X34721Y-26964 28 | X34721Y-28047 29 | X34721Y-28933 30 | X34721Y-29917 31 | X42319Y-21059 32 | X42319Y-22043 33 | X42319Y-23027 34 | X42319Y-25783 35 | X42319Y-26571 36 | X42319Y-27555 37 | X42319Y-28342 38 | X42319Y-29326 39 | X42319Y-30311 40 | T0 41 | M30 42 | -------------------------------------------------------------------------------- /pcb/gerber/openground_cc2500-Edge_Cuts.gbr: -------------------------------------------------------------------------------- 1 | G04 (created by PCBNEW (2013-jul-07)-stable) date Mon 10 Oct 2016 08:48:14 PM CEST* 2 | %MOIN*% 3 | G04 Gerber Fmt 3.4, Leading zero omitted, Abs format* 4 | %FSLAX34Y34*% 5 | G01* 6 | G70* 7 | G90* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.00590551*% 10 | %ADD11C,0.00393701*% 11 | G04 APERTURE END LIST* 12 | G54D10* 13 | G54D11* 14 | X35650Y-19550D02* 15 | X35650Y-16850D01* 16 | X34700Y-20500D02* 17 | X35650Y-19550D01* 18 | X34700Y-31300D02* 19 | X34700Y-20500D01* 20 | X42350Y-31300D02* 21 | X34700Y-31300D01* 22 | X42350Y-31000D02* 23 | X42350Y-31300D01* 24 | X42350Y-20500D02* 25 | X42350Y-31000D01* 26 | X44300Y-18550D02* 27 | X42350Y-20500D01* 28 | X44300Y-16850D02* 29 | X44300Y-18550D01* 30 | X35650Y-16850D02* 31 | X44300Y-16850D01* 32 | M02* 33 | -------------------------------------------------------------------------------- /pcb/gerber/openground_cc2500-B_Mask.gbs: -------------------------------------------------------------------------------- 1 | G04 (created by PCBNEW (2013-jul-07)-stable) date Mon 10 Oct 2016 08:48:14 PM CEST* 2 | %MOIN*% 3 | G04 Gerber Fmt 3.4, Leading zero omitted, Abs format* 4 | %FSLAX34Y34*% 5 | G01* 6 | G70* 7 | G90* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.00590551*% 10 | %ADD11R,0.0787402X0.0590551*% 11 | G04 APERTURE END LIST* 12 | G54D10* 13 | G54D11* 14 | X34878Y-29917D03* 15 | X34878Y-28932D03* 16 | X34878Y-28046D03* 17 | X34878Y-26964D03* 18 | X34878Y-25980D03* 19 | X34878Y-24798D03* 20 | X34878Y-22042D03* 21 | X34878Y-21058D03* 22 | X34878Y-23027D03* 23 | X42161Y-21058D03* 24 | X42161Y-22042D03* 25 | X42161Y-23027D03* 26 | X42161Y-25783D03* 27 | X42161Y-26570D03* 28 | X42161Y-27554D03* 29 | X42161Y-28342D03* 30 | X42161Y-29326D03* 31 | X42161Y-30310D03* 32 | M02* 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | 3 | addons: 4 | apt_packages: 5 | - lib32bz2-1.0 6 | - lib32ncurses5 7 | - lib32stdc++6 8 | 9 | cache: 10 | directories: 11 | - $HOME/gcc-arm-none-eabi-5_4-2016q2 12 | 13 | before_install: 14 | - export GCC_DIR=$HOME/gcc-arm-none-eabi-5_4-2016q2 15 | - export GCC_ARCHIVE=$HOME/gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 16 | - export GCC_URL=https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q2-update/+download/gcc-arm-none-eabi-5_4-2016q2-20160622-linux.tar.bz2 17 | - if [ ! -e $GCC_DIR/bin/arm-none-eabi-g++ ]; then wget $GCC_URL -O $GCC_ARCHIVE; tar xfj $GCC_ARCHIVE -C $HOME; fi 18 | - export PATH=$PATH:$GCC_DIR/bin 19 | - export TOOLROOT=$GCC_DIR/bin 20 | 21 | install: 22 | - cd $TRAVIS_BUILD_DIR 23 | - chmod +x .travis.sh 24 | 25 | language: c 26 | compiler: gcc 27 | 28 | script: ./.travis.sh 29 | -------------------------------------------------------------------------------- /src/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef MAIN_H_ 21 | #define MAIN_H_ 22 | 23 | #include "macros.h" 24 | 25 | #endif // MAIN_H_ 26 | -------------------------------------------------------------------------------- /src/wdt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef WDT_H_ 21 | #define WDT_H_ 22 | 23 | void wdt_init(void); 24 | void wdt_reset(void); 25 | 26 | #endif // WDT_H_ 27 | -------------------------------------------------------------------------------- /src/crc16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef CRC16_H_ 21 | #define CRC16_H_ 22 | 23 | #include 24 | 25 | uint16_t crc16(uint8_t *buf, uint16_t len); 26 | 27 | #endif // CRC16_H_ 28 | -------------------------------------------------------------------------------- /src/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef ASSERT_H__ 21 | #define ASSERT_H__ 22 | 23 | #include 24 | #include 25 | 26 | #define assert(x) cm3_assert(x) 27 | 28 | #endif // ASSERT_H_ 29 | -------------------------------------------------------------------------------- /src/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef DELAY_H_ 21 | #define DELAY_H_ 22 | 23 | #include 24 | #include "timeout.h" 25 | 26 | void delay_init(void); 27 | void delay_us(uint32_t us); 28 | #define delay_ms(ms) timeout_delay_ms(ms) 29 | 30 | 31 | #endif // DELAY_H_ 32 | -------------------------------------------------------------------------------- /src/clocksource.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef CLOCKSOURCE_H_ 21 | #define CLOCKSOURCE_H_ 22 | 23 | #include 24 | extern uint32_t rcc_timer_frequency; 25 | 26 | void clocksource_init(void); 27 | void clocksource_hse_in_8_out_48(void); 28 | 29 | #endif // CLOCKSOURCE_H_ 30 | -------------------------------------------------------------------------------- /src/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef USB_H_ 21 | #define USB_H_ 22 | 23 | #include 24 | #include "config.h" 25 | 26 | void usb_init(void); 27 | void usb_handle_systick(void); 28 | void usb_handle_data(void); 29 | bool usb_enabled(void); 30 | 31 | #endif // USB_H_ 32 | -------------------------------------------------------------------------------- /pcb/gerber/openground_cc2500-F_Mask.gts: -------------------------------------------------------------------------------- 1 | G04 (created by PCBNEW (2013-jul-07)-stable) date Mon 10 Oct 2016 08:48:14 PM CEST* 2 | %MOIN*% 3 | G04 Gerber Fmt 3.4, Leading zero omitted, Abs format* 4 | %FSLAX34Y34*% 5 | G01* 6 | G70* 7 | G90* 8 | G04 APERTURE LIST* 9 | %ADD10C,0.00590551*% 10 | %ADD11R,0.0787402X0.0590551*% 11 | %ADD12R,0.0590551X0.0787402*% 12 | G04 APERTURE END LIST* 13 | G54D10* 14 | G54D11* 15 | X34878Y-29917D03* 16 | X34878Y-28932D03* 17 | X34878Y-28046D03* 18 | X34878Y-26964D03* 19 | X34878Y-25980D03* 20 | X34878Y-24798D03* 21 | X34878Y-22042D03* 22 | X34878Y-21058D03* 23 | X34878Y-23027D03* 24 | X42161Y-21058D03* 25 | X42161Y-22042D03* 26 | X42161Y-23027D03* 27 | X42161Y-25783D03* 28 | X42161Y-26570D03* 29 | X42161Y-27554D03* 30 | X42161Y-28342D03* 31 | X42161Y-29326D03* 32 | X42161Y-30310D03* 33 | G54D12* 34 | X43580Y-17400D03* 35 | X42793Y-17400D03* 36 | X42005Y-17400D03* 37 | X41218Y-17400D03* 38 | X40431Y-17400D03* 39 | X39643Y-17400D03* 40 | X38856Y-17400D03* 41 | X38068Y-17400D03* 42 | X37281Y-17400D03* 43 | X36494Y-17400D03* 44 | X37281Y-30825D03* 45 | M02* 46 | -------------------------------------------------------------------------------- /src/font.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "font.h" 21 | 22 | // include fonts here and add an extern definition to font.h 23 | // DO NOT include them elsewhere 24 | #include "fonts/system5x7.h" 25 | #include "fonts/tomthumb3x5.h" 26 | #include "fonts/metric15x26.h" 27 | #include "fonts/metric7x12.h" 28 | -------------------------------------------------------------------------------- /src/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef IO_H_ 21 | #define IO_H_ 22 | 23 | #include 24 | 25 | void io_init(void); 26 | void io_init_gpio(void); 27 | void io_powerdown(void); 28 | void io_test_prepare(void); 29 | void io_test(void); 30 | 31 | uint32_t io_powerbutton_pressed(void); 32 | 33 | 34 | #endif // IO_H_ 35 | -------------------------------------------------------------------------------- /src/eeprom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef EEPROM_H_ 21 | #define EEPROM_H_ 22 | 23 | #include 24 | #include "storage.h" 25 | 26 | void eeprom_init(void); 27 | void eeprom_write_storage(void); 28 | void eeprom_read_storage(void); 29 | 30 | // init for st eeprom emulation, set up number of variables. 31 | #define EE_NB_OF_VAR ((uint16_t)(SIZEOF_STORAGE_IN_16BIT)) 32 | // extern uint16_t EE_virtual_address_table[EE_NB_OF_VAR]; 33 | 34 | #endif // EEPROM_H_ 35 | -------------------------------------------------------------------------------- /src/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef SPI_H_ 21 | #define SPI_H_ 22 | 23 | #include 24 | 25 | #include "config.h" 26 | #include "delay.h" 27 | 28 | void spi_init(void); 29 | void spi_dma_xfer(uint8_t *buffer, uint8_t len); 30 | #define spi_csn_lo() { gpio_clear(CC2500_SPI_GPIO, CC2500_SPI_CSN_PIN); delay_us(1); } 31 | #define spi_csn_hi() { delay_us(1); gpio_set(CC2500_SPI_GPIO, CC2500_SPI_CSN_PIN); } 32 | uint8_t spi_tx(uint8_t data); 33 | uint8_t spi_rx(void); 34 | uint8_t spi_read_address(uint8_t address); 35 | 36 | #endif // SPI_H_ 37 | 38 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef DEBUG_H_ 21 | #define DEBUG_H_ 22 | 23 | #include 24 | 25 | uint32_t debug_is_initialized(void); 26 | void debug_init(void); 27 | void debug_putc(uint8_t ch); 28 | void debug_flush(void); 29 | void debug(char *data); 30 | void debug_put_hex8(uint8_t val); 31 | void debug_put_hex16(uint16_t val); 32 | void debug_put_hex32(uint32_t val); 33 | void debug_put_uint8(uint8_t c); 34 | void debug_put_int8(int8_t c); 35 | void debug_put_uint16(uint16_t c); 36 | void debug_put_newline(void); 37 | void debug_put_fixed2(uint16_t c); 38 | 39 | #endif // DEBUG_H_ 40 | -------------------------------------------------------------------------------- /src/timeout.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef TIMEOUT_H_ 21 | #define TIMEOUT_H_ 22 | 23 | #include 24 | #include 25 | 26 | void timeout_init(void); 27 | // void timeout_set(__IO uint32_t ms); 28 | #define timeout_set(x) timeout_set_100us(10*(x)); 29 | void timeout_set_100us(__IO uint32_t hus); 30 | void timeout2_set_100us(__IO uint32_t hus); 31 | void timeout2_delay_100us(uint16_t us); 32 | uint8_t timeout_timed_out(void); 33 | uint8_t timeout2_timed_out(void); 34 | void timeout_delay_ms(uint32_t timeout); 35 | uint32_t timeout_time_remaining(void); 36 | 37 | #endif // TIMEOUT_H_ 38 | -------------------------------------------------------------------------------- /src/sound.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef SOUND_H_ 21 | #define SOUND_H_ 22 | 23 | #include 24 | #include 25 | 26 | extern volatile __IO uint32_t sound_tone_duration; 27 | 28 | void sound_init(void); 29 | 30 | typedef struct { 31 | uint16_t frequency; 32 | uint16_t duration_ms; 33 | } tone_t; 34 | 35 | void sound_enqueue(uint32_t freq, uint32_t duration_ms); 36 | void sound_set_frequency(uint32_t freq); 37 | void sound_play_click(void); 38 | void sound_play_low_time(void); 39 | void sound_play_bind(void); 40 | void sound_handle_playback(void); 41 | void sound_play_sample(tone_t *tone); 42 | 43 | #endif // SOUND_H_ 44 | -------------------------------------------------------------------------------- /src/crc16.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "crc16.h" 21 | 22 | // lookup table for crc16 CCITT 23 | static const uint16_t crc16_table[16] = { 24 | 0x0000, 0x1081, 0x2102, 0x3183, 0x4204, 0x5285, 0x6306, 0x7387, 25 | 0x8408, 0x9489, 0xA50A, 0xB58B, 0xC60C, 0xD68D, 0xE70E, 0xF78F 26 | }; 27 | 28 | static uint16_t crc16_update(uint16_t crc, uint8_t c) { 29 | crc = (((crc >> 4) & 0x0FFF) ^ crc16_table[((crc ^ c) & 0x000F)]); 30 | crc = (((crc >> 4) & 0x0FFF) ^ crc16_table[((crc ^ (c>>4)) & 0x000F)]); 31 | return crc; 32 | } 33 | 34 | uint16_t crc16(uint8_t *buf, uint16_t len) { 35 | uint16_t crc = 0; 36 | while (len--) { 37 | crc = crc16_update(crc, *buf++); 38 | } 39 | return crc; 40 | } 41 | -------------------------------------------------------------------------------- /src/font.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef FONT_H_ 21 | #define FONT_H_ 22 | 23 | #include 24 | 25 | // font indices 26 | #define FONT_LENGTH 0 27 | #define FONT_FIXED_WIDTH 2 28 | #define FONT_HEIGHT 3 29 | #define FONT_FIRST_CHAR 4 30 | #define FONT_CHAR_COUNT 5 31 | #define FONT_WIDTH_TABLE 6 32 | 33 | // helpers 34 | #define font_is_fixed_width(_f) ((_f[FONT_LENGTH] == 0) && (_f[FONT_LENGTH+1] < 2)) 35 | #define font_is_nopad_fixed_font(_f) ((_f[FONT_LENGTH] == 0) && (_f[FONT_LENGTH+1] == 1)) 36 | 37 | extern const uint8_t font_system5x7[]; 38 | extern const uint8_t font_tomthumb3x5[]; 39 | extern const uint8_t font_metric15x26[]; 40 | extern const uint8_t font_metric7x12[]; 41 | 42 | #endif // FONT_H_ 43 | -------------------------------------------------------------------------------- /src/wdt.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "wdt.h" 21 | #include "debug.h" 22 | #include "delay.h" 23 | #include 24 | #include 25 | 26 | void wdt_init(void) { 27 | // detect resets from wdt 28 | if (RCC_CSR & RCC_CSR_IWDGRSTF) { 29 | debug("hal_wdt: watchdog reset detected\n"); debug_flush(); 30 | RCC_CSR &= ~(RCC_CSR_IWDGRSTF); 31 | } 32 | 33 | // set wdg timeout to roughly 1000ms(varies due to LSI freq dispersion) 34 | iwdg_set_period_ms(1000); 35 | 36 | // enable IWDG(the LSI oscillator will be enabled by hardware) 37 | iwdg_start(); 38 | } 39 | 40 | inline void wdt_reset(void) { 41 | // reset wdt 42 | iwdg_reset(); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/delay.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | 21 | #include "delay.h" 22 | 23 | void delay_init(void) { 24 | // nothing to do 25 | } 26 | 27 | 28 | inline void delay_us(uint32_t us) { 29 | // based on https:// github.com/leaflabs/libmaple 30 | us *= 8; 31 | 32 | // fudge for function call overhead 33 | us--; 34 | us--; 35 | us--; 36 | us--; 37 | us--; 38 | us--; 39 | us--; 40 | asm volatile(".syntax unified \n\t" 41 | " mov r0, %[us] \n\t" 42 | "1: subs r0, #1 \n\t" 43 | " bhi 1b \n\t" 44 | ".syntax divided \n\t" 45 | : 46 | : [us] "r" (us) 47 | : "r0"); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/telemetry.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef TELEMETRY_H_ 21 | #define TELEMETRY_H_ 22 | 23 | #include 24 | #include "fifo.h" 25 | 26 | void telemetry_init(void); 27 | void telemetry_enqueue(uint8_t byte); 28 | void telemetry_process(void); 29 | 30 | uint16_t telemetry_get_voltage(void); 31 | uint16_t telemetry_get_current(void); 32 | uint16_t telemetry_get_mah(void); 33 | 34 | // FrSky telemetry stream state machine 35 | typedef enum { 36 | TELEMETRY_IDLE = 0, // waiting for 0x5e frame marker 37 | TELEMETRY_DATA_ID, // waiting for dataID 38 | TELEMETRY_DATA_LOW, // waiting for data low byte 39 | TELEMETRY_DATA_HIGH, // waiting for data high byte 40 | TELEMETRY_DATA_END, // waiting for 0x5e end of frame marker 41 | TELEMETRY_XOR = 0x80 // decode stuffed byte 42 | } telemetry_state_t; 43 | 44 | 45 | #endif // TELEMETRY_H_ 46 | -------------------------------------------------------------------------------- /src/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef LED_H_ 21 | #define LED_H_ 22 | 23 | #include 24 | #include "config.h" 25 | 26 | void led_init(void); 27 | 28 | #define led_backlight_on() { gpio_set(LED_BACKLIGHT_GPIO, LED_BACKLIGHT_PIN); } 29 | #define led_backlight_off() { gpio_clear(LED_BACKLIGHT_GPIO, LED_BACKLIGHT_PIN); } 30 | #define led_backlight_toggle() { gpio_toggle(LED_BACKLIGHT_GPIO, LED_BACKLIGHT_PIN); } 31 | 32 | #define led_button_r_on() { gpio_set(LED_BUTTON_R_GPIO, LED_BUTTON_R_PIN); } 33 | #define led_button_r_off() { gpio_clear(LED_BUTTON_R_GPIO, LED_BUTTON_R_PIN); } 34 | #define led_button_r_toggle() { gpio_toggle(LED_BUTTON_R_GPIO, LED_BUTTON_R_PIN); } 35 | 36 | #define led_button_l_on() { gpio_set(LED_BUTTON_L_GPIO, LED_BUTTON_L_PIN); } 37 | #define led_button_l_off() { gpio_clear(LED_BUTTON_L_GPIO, LED_BUTTON_L_PIN); } 38 | #define led_button_l_toggle() { gpio_toggle(LED_BUTTON_L_GPIO, LED_BUTTON_L_PIN); } 39 | 40 | #endif // LED_H_ 41 | -------------------------------------------------------------------------------- /linker/stm32f072.ld: -------------------------------------------------------------------------------- 1 | EXTERN(vector_table) 2 | ENTRY(reset_handler) 3 | 4 | /* reserve two pages for eeprom emulation */ 5 | _emulated_eeprom_page_size = 2048; /* do not change this, stm32f072 has 2k pagesize */ 6 | _emulated_eeprom_size = 2*_emulated_eeprom_page_size; 7 | 8 | MEMORY 9 | { 10 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K 11 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K 12 | EMULATED_EEPROM (rwx) : ORIGIN = 0x8000000+128K-2*2048 LENGTH=2*2048 13 | } 14 | 15 | 16 | /*EMULATED_EEPROM;*/ 17 | _emulated_eeprom = 0x08011800; /*ORIGIN(EMULATED_EEPROM);*/ 18 | 19 | 20 | SECTIONS 21 | { 22 | .text : { 23 | *(.vectors) 24 | *(.text*) 25 | . = ALIGN(4); 26 | *(.rodata*) 27 | . = ALIGN(4); 28 | } >rom 29 | .preinit_array : { 30 | . = ALIGN(4); 31 | __preinit_array_start = .; 32 | KEEP (*(.preinit_array)) 33 | __preinit_array_end = .; 34 | } >rom 35 | .init_array : { 36 | . = ALIGN(4); 37 | __init_array_start = .; 38 | KEEP (*(SORT(.init_array.*))) 39 | KEEP (*(.init_array)) 40 | __init_array_end = .; 41 | } >rom 42 | .fini_array : { 43 | . = ALIGN(4); 44 | __fini_array_start = .; 45 | KEEP (*(.fini_array)) 46 | KEEP (*(SORT(.fini_array.*))) 47 | __fini_array_end = .; 48 | } >rom 49 | .ARM.extab : { 50 | *(.ARM.extab*) 51 | } >rom 52 | .ARM.exidx : { 53 | __exidx_start = .; 54 | *(.ARM.exidx*) 55 | __exidx_end = .; 56 | } >rom 57 | . = ALIGN(4); 58 | _etext = .; 59 | .data : { 60 | _data = .; 61 | *(.data*) 62 | . = ALIGN(4); 63 | _edata = .; 64 | } >ram AT >rom 65 | _data_loadaddr = LOADADDR(.data); 66 | .bss : { 67 | *(.bss*) 68 | *(COMMON) 69 | . = ALIGN(4); 70 | _ebss = .; 71 | } >ram 72 | /DISCARD/ : { *(.eh_frame) } 73 | . = ALIGN(4); 74 | end = .; 75 | } 76 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 77 | -------------------------------------------------------------------------------- /src/assert.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include 21 | 22 | #include "debug.h" 23 | #include "console.h" 24 | #include "led.h" 25 | #include "delay.h" 26 | #include "screen.h" 27 | #include "macros.h" 28 | #include "assert.h" 29 | #include 30 | 31 | void cm3_assert_failed_verbose(const char *filename, int line, const char *func, const char *UNUSED(assert_expr)) { 32 | // report position 33 | if (debug_is_initialized()) { 34 | debug("!ASSERT: line "); 35 | debug_put_uint16(line); 36 | debug("\n func: "); 37 | debug((char*)func); 38 | debug("\nin "); 39 | debug((char*) filename); 40 | debug_put_newline(); 41 | debug_flush(); 42 | console_render(); 43 | screen_update(); 44 | } 45 | 46 | // infinite loop 47 | led_button_r_off(); 48 | led_button_l_on(); 49 | while (1) { 50 | led_button_r_toggle(); 51 | led_button_l_toggle(); 52 | delay_us(50*1000); 53 | } 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef CONSOLE_H_ 21 | #define CONSOLE_H_ 22 | 23 | #include 24 | #include "font.h" 25 | 26 | // rendering color for text, background is the inverse (allowed: 0,1) 27 | #define CONSOLE_TEXTCOLOR 0 28 | 29 | void console_init(void); 30 | void console_clear(void); 31 | 32 | // static void console_render_str(uint8_t line, uint8_t color, char *str); 33 | void console_puts(char *str); 34 | void console_putc(char c); 35 | void console_render(void); 36 | 37 | // you can define the console font here. make sure to use FIXED WIDTH fonts! 38 | // make sure to set width and height properly 39 | // #define CONSOLE_FONT font_system5x7 40 | #define CONSOLE_FONT font_tomthumb3x5 41 | #define CONSOLE_FONT_WIDTH 3 42 | #define CONSOLE_FONT_HEIGHT 5 43 | 44 | // calculate how many chars can be printed on the console 45 | #define CONSOLE_BUFFER_SIZE_X (LCD_WIDTH / (CONSOLE_FONT_WIDTH+1)) 46 | #define CONSOLE_BUFFER_SIZE_Y ((LCD_HEIGHT / (CONSOLE_FONT_HEIGHT+1))+1) 47 | 48 | #endif // CONSOLE_H_ 49 | 50 | -------------------------------------------------------------------------------- /src/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "config.h" 21 | #include 22 | #include 23 | 24 | config_hw_revision_t config_hw_revision; 25 | 26 | void config_init(void) { 27 | config_detect_hw_revision(); 28 | } 29 | 30 | // autodetect hw revision works as follows: 31 | // tgy evolution has a pulldown on RF0 (=PE.10) 32 | void config_detect_hw_revision(void) { 33 | // enable peripheral clock 34 | rcc_periph_clock_enable(GPIO_RCC(HW_REVISION_GPIO)); 35 | 36 | // init PE.10 as intput with PULLUP 37 | gpio_mode_setup(HW_REVISION_GPIO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, HW_REVISION_PIN); 38 | gpio_set_output_options(HW_REVISION_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, HW_REVISION_PIN); 39 | 40 | // now we can check for the pullwon resistor: 41 | if (gpio_get(HW_REVISION_GPIO, HW_REVISION_PIN) == 0) { 42 | // pulled down -> tgy evolution 43 | config_hw_revision = CONFIG_HW_REVISION_EVOLUTION; 44 | } else { 45 | // no pulldown -> high -> i6s 46 | config_hw_revision = CONFIG_HW_REVISION_I6S; 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/led.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "led.h" 21 | #include "macros.h" 22 | #include 23 | 24 | void led_init(void) { 25 | // peripheral clocks enable 26 | rcc_periph_clock_enable(GPIO_RCC(LED_BACKLIGHT_GPIO)); 27 | rcc_periph_clock_enable(GPIO_RCC(LED_BUTTON_R_GPIO)); 28 | rcc_periph_clock_enable(GPIO_RCC(LED_BUTTON_L_GPIO)); 29 | 30 | // set led pin as output 31 | gpio_mode_setup(LED_BACKLIGHT_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_BACKLIGHT_PIN); 32 | gpio_set_output_options(LED_BACKLIGHT_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, LED_BACKLIGHT_PIN); 33 | 34 | // left button led 35 | gpio_mode_setup(LED_BUTTON_L_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_BUTTON_L_PIN); 36 | gpio_set_output_options(LED_BUTTON_L_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, LED_BUTTON_L_PIN); 37 | 38 | // right button led 39 | gpio_mode_setup(LED_BUTTON_R_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_BUTTON_R_PIN); 40 | gpio_set_output_options(LED_BUTTON_R_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, LED_BUTTON_R_PIN); 41 | 42 | led_button_l_on(); 43 | led_button_r_on(); 44 | 45 | led_backlight_on(); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/adc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef ADC_H_ 21 | #define ADC_H_ 22 | #include 23 | #include 24 | #include "main.h" 25 | 26 | void adc_init(void); 27 | void adc_test(void); 28 | 29 | void adc_process(void); 30 | 31 | uint16_t adc_get_channel(uint32_t id); 32 | int32_t adc_get_channel_rescaled(uint8_t idx); 33 | uint16_t adc_get_channel_packetdata(uint8_t idx); 34 | uint32_t adc_get_battery_voltage(void); 35 | 36 | // internal channel ordering. we will always use AETR0123 internally 37 | typedef enum { 38 | CHANNEL_ID_AILERON = 0, 39 | CHANNEL_ID_ELEVATION, 40 | CHANNEL_ID_THROTTLE, 41 | CHANNEL_ID_RUDDER, 42 | CHANNEL_ID_CH0, 43 | CHANNEL_ID_CH1, 44 | CHANNEL_ID_CH2, 45 | CHANNEL_ID_CH3, 46 | CHANNEL_ID_SIZE 47 | } channel_id_t; 48 | 49 | char *adc_get_channel_name(uint8_t i, bool short_descr); 50 | 51 | 52 | // rescaled data goes from -3200 to 3200 53 | // set zero threshold to 10% movement from absolute zero 54 | #define ADC_RESCALED_ABSOLUTE_MIN -3200 55 | #define ADC_RESCALED_ABSOLUTE_MAX 3200 56 | #define ADC_RESCALED_ZERO_THRESHOLD (ADC_RESCALED_ABSOLUTE_MIN + 0.1 * \ 57 | (ADC_RESCALED_ABSOLUTE_MAX - ADC_RESCALED_ABSOLUTE_MIN)) 58 | 59 | 60 | #endif // ADC_H_ 61 | -------------------------------------------------------------------------------- /OpenGround.includes: -------------------------------------------------------------------------------- 1 | . 2 | core 3 | device 4 | fonts 5 | peripheral_lib/inc 6 | src 7 | libopencm3/include/libopencm3/stm32/f3 8 | libopencm3/lib/stm32/l4 9 | libopencm3/include/libopencm3/stm32/f2 10 | libopencm3/include/libopencm3/lm4f 11 | libopencm3/lib/stm32/f3 12 | libopencm3/include/libopencm3/stm32/l1 13 | libopencm3/include/libopencm3/sam/3u 14 | libopencm3/include/libopencm3/stm32/common 15 | libopencm3/include/libopencm3/sam/3a 16 | peripheral_lib/eeprom_emulation/inc 17 | libopencm3/include/libopencm3/lpc43xx 18 | libopencm3/lib/stm32/common 19 | libopencm3/include/libopencm3/lpc13xx 20 | libopencm3/include/libopencm3/sam/3n 21 | libopencm3/include/libopencm3/stm32/l4 22 | peripheral_lib/eeprom_emulation/src 23 | libopencm3/include/libopencm3/sam/3s 24 | libopencm3/include/libopencm3/sam 25 | libopencm3/lib/stm32/f0 26 | libopencm3/lib/stm32/l0 27 | libopencm3/include/libopencm3/usb 28 | libopencm3/lib/stm32 29 | peripheral_lib/src 30 | libopencm3/include/libopencm3/efm32/tg 31 | libopencm3/include/libopencm3/ethernet 32 | libopencm3/lib/stm32/l1 33 | libopencm3/lib/stm32/f2 34 | libopencm3/include/libopencm3/stm32 35 | libopencm3/include/libopencm3/efm32 36 | libopencm3/lib/stm32/f4 37 | libopencm3/include/libopencm3/sam/3x 38 | libopencm3/include/libopencmsis 39 | libopencm3/include/libopencm3/stm32/f7 40 | libopencm3/include/libopencm3/lm3s 41 | libopencm3/include/libopencm3/sam/common 42 | libopencm3/lib/stm32/f7 43 | libopencm3/include/libopencm3/cm3 44 | libopencm3/include/libopencm3/efm32/lg 45 | libopencm3/lib/stm32/f1 46 | libopencm3/include/libopencm3/sam/d 47 | stylecheck 48 | libopencm3/include/libopencm3/stm32/f0 49 | libopencm3/lib/usb 50 | libopencm3/include/libopencm3/dispatch 51 | libopencm3/include/libopencmsis/dispatch 52 | libopencm3/include/libopencm3/efm32/g 53 | libopencm3/include/libopencm3/efm32/gg 54 | libopencm3/lib/cm3 55 | libopencm3/include/libopencm3/stm32/f4 56 | libopencm3/include/libopencm3/stm32/l0 57 | libopencm3/include/libopencm3/lpc17xx 58 | libopencm3/include/libopencm3/vf6xx 59 | libopencm3/include/libopencm3/stm32/f1 60 | src/eeprom_emulation 61 | -------------------------------------------------------------------------------- /pcb/openground_cc2500.pro: -------------------------------------------------------------------------------- 1 | update=Wed 05 Oct 2016 11:03:51 AM CEST 2 | version=1 3 | last_client=pcbnew 4 | [cvpcb] 5 | version=1 6 | NetIExt=net 7 | [cvpcb/libraries] 8 | EquName1=devcms 9 | [general] 10 | version=1 11 | [eeschema] 12 | version=1 13 | LibDir=../pcb 14 | NetFmtName= 15 | RptD_X=0 16 | RptD_Y=100 17 | RptLab=1 18 | LabSize=60 19 | [eeschema/libraries] 20 | LibName1=power 21 | LibName2=device 22 | LibName3=transistors 23 | LibName4=conn 24 | LibName5=linear 25 | LibName6=regul 26 | LibName7=74xx 27 | LibName8=cmos4000 28 | LibName9=adc-dac 29 | LibName10=memory 30 | LibName11=xilinx 31 | LibName12=special 32 | LibName13=microcontrollers 33 | LibName14=dsp 34 | LibName15=microchip 35 | LibName16=analog_switches 36 | LibName17=motorola 37 | LibName18=texas 38 | LibName19=intel 39 | LibName20=audio 40 | LibName21=interface 41 | LibName22=digital-audio 42 | LibName23=philips 43 | LibName24=display 44 | LibName25=cypress 45 | LibName26=siliconi 46 | LibName27=opto 47 | LibName28=atmel 48 | LibName29=contrib 49 | LibName30=valves 50 | LibName31=custom 51 | [pcbnew] 52 | version=1 53 | LastNetListRead= 54 | UseCmpFile=1 55 | PadDrill=" 0.600000" 56 | PadDrillOvalY=" 0.600000" 57 | PadSizeH=" 1.500000" 58 | PadSizeV=" 1.500000" 59 | PcbTextSizeV=" 1.500000" 60 | PcbTextSizeH=" 1.500000" 61 | PcbTextThickness=" 0.300000" 62 | ModuleTextSizeV=" 1.000000" 63 | ModuleTextSizeH=" 1.000000" 64 | ModuleTextSizeThickness=" 0.150000" 65 | SolderMaskClearance=" 0.000000" 66 | SolderMaskMinWidth=" 0.000000" 67 | DrawSegmentWidth=" 0.200000" 68 | BoardOutlineThickness=" 0.100000" 69 | ModuleOutlineThickness=" 0.150000" 70 | [pcbnew/libraries] 71 | LibDir= 72 | LibName1=sockets 73 | LibName2=connect 74 | LibName3=discret 75 | LibName4=pin_array 76 | LibName5=divers 77 | LibName6=smd_capacitors 78 | LibName7=smd_resistors 79 | LibName8=smd_crystal&oscillator 80 | LibName9=smd_dil 81 | LibName10=smd_transistors 82 | LibName11=libcms 83 | LibName12=display 84 | LibName13=led 85 | LibName14=dip_sockets 86 | LibName15=pga_sockets 87 | LibName16=valves 88 | LibName17=custom 89 | -------------------------------------------------------------------------------- /stylecheck/README: -------------------------------------------------------------------------------- 1 | This is automated checker to make sure a C++ file follows Google's C++ style 2 | guide (https://google.github.io/styleguide/cppguide.html). As it 3 | heavily relies on regular expressions, cpplint.py won't catch all violations of 4 | the style guide and will very occasionally report a false positive. There is a 5 | list of things we currently don't handle very well at the top of cpplint.py, 6 | and we welcome patches to improve it. 7 | 8 | The linting tool takes a list of files as input. For full usage instructions, 9 | please see the output of: 10 | 11 | ./cpplint.py --help 12 | 13 | Unit tests are provided in cpplint_unittest.py. This file can safely be ignored 14 | by end users who have downloaded this package and only want to run the lint 15 | tool. 16 | 17 | --- 18 | 19 | cpplint.py and its corresponding unit tests are Copyright (C) 2009 Google Inc. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are 23 | met: 24 | 25 | * Redistributions of source code must retain the above copyright 26 | notice, this list of conditions and the following disclaimer. 27 | * Redistributions in binary form must reproduce the above 28 | copyright notice, this list of conditions and the following disclaimer 29 | in the documentation and/or other materials provided with the 30 | distribution. 31 | * Neither the name of Google Inc. nor the names of its 32 | contributors may be used to endorse or promote products derived from 33 | this software without specific prior written permission. 34 | 35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | -------------------------------------------------------------------------------- /src/storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef STORAGE_H_ 21 | #define STORAGE_H_ 22 | 23 | #include 24 | 25 | #include "frsky.h" 26 | 27 | #define STORAGE_VERSION_ID 0x03 28 | #define STORAGE_MODEL_NAME_LEN 11 29 | #define STORAGE_MODEL_MAX_COUNT 10 30 | 31 | void storage_init(void); 32 | // static void storage_init_memory(void); 33 | // void storage_write_to_flash(void); 34 | // static void storage_read_from_flash(void); 35 | void storage_save(void); 36 | void storage_load(void); 37 | void storage_mode_set_name(uint8_t index, char *str); 38 | /*static void storage_write(uint8_t *buffer, uint16_t len); 39 | static void storage_read(uint8_t *storage_ptr, uint16_t len);*/ 40 | 41 | // model description 42 | typedef struct { 43 | // name of the model 44 | char name[STORAGE_MODEL_NAME_LEN]; 45 | // timer 46 | uint16_t timer; 47 | // scale 48 | uint8_t stick_scale; 49 | // add further data here... 50 | } MODEL_DESC; 51 | 52 | // our storage struct contains all data that has to be stored on flash 53 | typedef struct { 54 | // version id 55 | uint8_t version; 56 | // persistent storage for frsky 57 | uint8_t frsky_txid[2]; 58 | uint8_t frsky_hop_table[FRSKY_HOPTABLE_SIZE]; 59 | int8_t frsky_freq_offset; 60 | // stick calibration data 61 | uint16_t stick_calibration[4][3]; 62 | // model settings 63 | uint8_t current_model; 64 | MODEL_DESC model[STORAGE_MODEL_MAX_COUNT]; 65 | // new data should be placed BEFORE the checksum... 66 | // 67 | // checksum 68 | uint16_t checksum; 69 | } STORAGE_DESC; 70 | 71 | // rounded up 72 | #define SIZEOF_STORAGE_IN_16BIT ((sizeof(storage) + 1) / 2) 73 | 74 | extern STORAGE_DESC storage; 75 | 76 | #endif // STORAGE_H_ 77 | -------------------------------------------------------------------------------- /src/fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 fishpepper 3 | Copyright (C) 2008 by Steve Karg 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to: 17 | The Free Software Foundation, Inc. 18 | 59 Temple Place - Suite 330 19 | Boston, MA 02111-1307 20 | USA. 21 | 22 | As a special exception, if other files instantiate templates or 23 | use macros or inline functions from this file, or you compile 24 | this file and link it with other works to produce a work based 25 | on this file, this file does not by itself cause the resulting 26 | work to be covered by the GNU General Public License. However 27 | the source code for this file must still be made available in 28 | accordance with section (3) of the GNU General Public License. 29 | 30 | This exception does not invalidate any other reasons why a work 31 | based on this file might be covered by the GNU General Public 32 | License.*/ 33 | 34 | /* Functional Description: Generic FIFO library for deeply 35 | embedded system. See the unit tests for usage examples. 36 | This library only uses a byte sized chunk. 37 | This library is designed for use in Interrupt Service Routines 38 | and so is declared as "static inline" */ 39 | 40 | #ifndef FIFO_H__ 41 | #define FIFO_H__ 42 | 43 | #include 44 | #include 45 | 46 | typedef struct { 47 | volatile unsigned head; /* first byte of data */ 48 | volatile unsigned tail; /* last byte of data */ 49 | volatile uint8_t *buffer; /* block of memory or array of data */ 50 | unsigned buffer_len; /* length of the data */ 51 | } fifo_buffer_t; 52 | 53 | bool fifo_empty(fifo_buffer_t const *b); 54 | 55 | uint8_t fifo_peek(fifo_buffer_t const *b); 56 | 57 | uint8_t fifo_get(fifo_buffer_t * b); 58 | 59 | bool fifo_put(fifo_buffer_t * b, uint8_t data_byte); 60 | 61 | /* note: buffer_len must be a power of two */ 62 | void fifo_init(fifo_buffer_t * b, volatile uint8_t *buffer, unsigned buffer_len); 63 | 64 | #endif // FIFO_H__ 65 | -------------------------------------------------------------------------------- /scripts/generate_hoptable.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # this will generate a random frsky compatible 4 | # hop table and a random txid 5 | # 6 | import random 7 | import textwrap 8 | 9 | random.seed() 10 | 11 | #get a random number for the txid 12 | txid = random.randint(513, 65000) 13 | 14 | hoptable_ok = 0 15 | 16 | #generate hoptable 17 | hoptable_ok = 0 18 | while (hoptable_ok == 0): 19 | #get random numbers for the hoptable calculation 20 | channel_start = random.randint(0, 7) 21 | channel_spacing = random.randint(64, 255-64) 22 | 23 | hoptable = [] 24 | hop = channel_start 25 | for i in range(47): 26 | hoptable.append(hop) 27 | hop = (hop + channel_spacing) % 235 28 | if (hop == 0) or (hop == 0x5A) or (hop == 0xDC): 29 | hop = hop + 1 30 | 31 | #verify that there is no hop more than one time 32 | hoptable_ok = 1 33 | for x in range(235): 34 | count = hoptable.count(x) 35 | if (count > 1): 36 | #invalid hoptable, try again 37 | #print hoptable.count(x) 38 | hoptable_ok = 0 39 | 40 | #great, valid hoptable found 41 | hoptable_s = (", ".join(hex(x) for x in hoptable)) 42 | 43 | print("/*"); 44 | print(" Copyright 2016 fishpepper gmail.com"); 45 | print(""); 46 | print(" This program is free software: you can redistribute it and/or modify"); 47 | print(" it under the terms of the GNU General Public License as published by"); 48 | print(" the Free Software Foundation, either version 3 of the License, or"); 49 | print(" (at your option) any later version."); 50 | print(""); 51 | print(" This program is distributed in the hope that it will be useful,"); 52 | print(" but WITHOUT ANY WARRANTY; without even the implied warranty of"); 53 | print(" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"); 54 | print(" GNU General Public License for more details."); 55 | print(""); 56 | print(" You should have received a copy of the GNU General Public License"); 57 | print(" along with this program. If not, see ."); 58 | print(""); 59 | print(" author: fishpepper gmail.com"); 60 | print("*/"); 61 | print("#ifndef HOPTABLE_H_"); 62 | print("#define HOPTABLE_H_"); 63 | print(""); 64 | print("#define FRSKY_DEFAULT_FSCAL_VALUE 0x00"); 65 | print(""); 66 | print("#define FRSYK_TXID (0x%04X)" % (txid)) 67 | print("") 68 | print("// hoptable was generated with start=%d, spacing=%d" % (channel_start, channel_spacing)) 69 | print("#define FRSKY_HOPTABLE { \\") 70 | for x in textwrap.wrap(hoptable_s): 71 | print("%s \\" % (x)) 72 | print("};"); 73 | print("") 74 | print("#endif // HOPTABLE_H_") 75 | -------------------------------------------------------------------------------- /device/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f0xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F0XX_H 40 | #define __SYSTEM_STM32F0XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F0xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F0xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @addtogroup STM32F0xx_System_Exported_Constants 66 | * @{ 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @addtogroup STM32F0xx_System_Exported_Macros 74 | * @{ 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @addtogroup STM32F0xx_System_Exported_Functions 82 | * @{ 83 | */ 84 | 85 | extern void SystemInit(void); 86 | extern void SystemCoreClockUpdate(void); 87 | /** 88 | * @} 89 | */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /*__SYSTEM_STM32F0XX_H */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /src/gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef GUI_H_ 21 | #define GUI_H_ 22 | 23 | #include 24 | #include "adc.h" 25 | 26 | #define GUI_PREV_CLICK_X 10 27 | #define GUI_NEXT_CLICK_X (LCD_WIDTH - GUI_PREV_CLICK_X) 28 | #define GUI_PAGE_MAIN 0 29 | #define GUI_PAGE_STICKS 1 30 | #define GUI_PAGE_SETTINGS 2 31 | #define GUI_MAX_PAGE GUI_PAGE_SETTINGS 32 | #define GUI_STATUSBAR_FONT font_tomthumb3x5 33 | 34 | 35 | #define GUI_LOOP_DELAY_MS 100 36 | #define GUI_SHUTDOWN_PRESS_S 2.0 37 | #define GUI_SHUTDOWN_PRESS_COUNT_FROM_MS(_ms) ((_ms)/GUI_LOOP_DELAY_MS) 38 | #define GUI_SHUTDOWN_PRESS_COUNT (GUI_SHUTDOWN_PRESS_COUNT_FROM_MS(1000*GUI_SHUTDOWN_PRESS_S)) 39 | 40 | // touch function pointer 41 | typedef void (*f_ptr_t)(void); 42 | typedef void (*f_ptr_32_32_t)(uint32_t x, uint32_t y); 43 | 44 | // touch callback 45 | typedef struct { 46 | // defines the touch sensitive rect 47 | uint8_t xs; 48 | uint8_t xe; 49 | uint8_t ys; 50 | uint8_t ye; 51 | // and the callback to run 52 | f_ptr_t callback; 53 | } touch_callback_entry_t; 54 | 55 | #define GUI_TOUCH_CALLBACK_COUNT 10 56 | 57 | 58 | #define GUI_PAGE_CONFIG_FLAG 0x80 59 | #define GUI_PAGE_CONFIG_OPTION_FLAG 0x40 60 | #define GUI_PAGE_SETUP_FLAG 0x20 61 | #define GUI_PAGE_NOFLAGS (~(GUI_PAGE_CONFIG_FLAG|GUI_PAGE_CONFIG_OPTION_FLAG|GUI_PAGE_SETUP_FLAG)) 62 | 63 | 64 | #define GUI_PAGE_SETUP_MAIN (GUI_PAGE_SETUP_FLAG | 0) 65 | #define GUI_PAGE_SETUP_CLONETX (GUI_PAGE_SETUP_FLAG | 1) 66 | #define GUI_PAGE_SETUP_BIND (GUI_PAGE_SETUP_FLAG | 2) 67 | #define GUI_PAGE_SETUP_BOOTLOADER (GUI_PAGE_SETUP_FLAG | 3) 68 | 69 | #define GUI_PAGE_CONFIG_MAIN (GUI_PAGE_CONFIG_FLAG | 0) 70 | #define GUI_PAGE_CONFIG_STICK_CAL (GUI_PAGE_CONFIG_FLAG | 1) 71 | #define GUI_PAGE_CONFIG_MODEL_SETTINGS (GUI_PAGE_CONFIG_FLAG | 2) 72 | 73 | 74 | #define GUI_SUBPAGE_SETTING_MODEL_NAME 0 75 | #define GUI_SUBPAGE_SETTING_MODEL_SCALE 1 76 | #define GUI_SUBPAGE_SETTING_MODEL_TIMER 2 77 | 78 | void gui_init(void); 79 | void gui_loop(void); 80 | 81 | uint32_t gui_running(void); 82 | 83 | 84 | #endif // GUI_H_ 85 | -------------------------------------------------------------------------------- /src/clocksource.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "clocksource.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | uint32_t rcc_timer_frequency; 27 | 28 | void clocksource_init(void) { 29 | // set clock source 30 | clocksource_hse_in_8_out_48(); 31 | } 32 | 33 | void clocksource_hse_in_8_out_48(void) { 34 | // see 35 | // https://www.mikrocontroller.net/attachment/322047/Clock_Control.png 36 | // or RM00091 p. 98 37 | 38 | // enable internal high-speed oscillator 39 | rcc_osc_on(RCC_HSI); 40 | rcc_wait_for_osc_ready(RCC_HSI); 41 | 42 | // Select HSI as SYSCLK source. 43 | rcc_set_sysclk_source(RCC_CFGR_SW_HSI); 44 | 45 | // Enable external high-speed oscillator 8MHz 46 | rcc_osc_on(RCC_HSE); 47 | rcc_wait_for_osc_ready(RCC_HSE); 48 | rcc_set_sysclk_source(RCC_CFGR_SW_HSE); 49 | 50 | // set prescalers for AHB, ADC, ABP1, ABP2. 51 | // Do this before touching the PLL 52 | rcc_set_hpre(RCC_CFGR_HPRE_NODIV); // 48Mhz (max 72) 53 | rcc_set_ppre(RCC_CFGR_PPRE_DIV2); // 24Mhz (max 36) 54 | 55 | // sysclk runs with 48MHz -> 1 waitstates. 56 | // * 0WS from 0-24MHz 57 | // * 1WS from 24-48MHz 58 | // * 2WS from 48-72MHz 59 | flash_set_ws(FLASH_ACR_LATENCY_1WS); 60 | 61 | // set the PLL multiplication factor to 6 62 | // pll source is hse 63 | RCC_CFGR |= RCC_CFGR_PLLSRC; 64 | // pll prediv = 1 65 | rcc_set_prediv(RCC_CFGR2_PREDIV_NODIV); 66 | // 8MHz (external) * 6 (multiplier) = 48MHz 67 | rcc_set_pll_multiplication_factor(RCC_CFGR_PLLMUL_MUL6); 68 | 69 | // enable PLL oscillator and wait for it to stabilize. 70 | rcc_osc_on(RCC_PLL); 71 | rcc_wait_for_osc_ready(RCC_PLL); 72 | 73 | // select PLL as SYSCLK source. 74 | rcc_set_sysclk_source(RCC_PLL); 75 | 76 | // set the peripheral clock frequencies used */ 77 | rcc_ahb_frequency = 48000000; 78 | rcc_apb1_frequency = 24000000; 79 | 80 | // When PPRE is set to something != NODIV 81 | // TIM input clock is apb clkspeed*2 (see RM00091 p98) 82 | rcc_timer_frequency = 2*rcc_apb1_frequency; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/timeout.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "timeout.h" 21 | #include "debug.h" 22 | #include "delay.h" 23 | #include "led.h" 24 | #include "sound.h" 25 | #include "usb.h" 26 | #include 27 | #include 28 | #include 29 | 30 | static volatile __IO uint32_t timeout_100us; 31 | static volatile __IO uint32_t timeout2_100us; 32 | static volatile __IO uint32_t timeout_100us_delay; 33 | 34 | void timeout_init(void) { 35 | debug("timeout: init\n"); debug_flush(); 36 | 37 | // configure 0.1ms sys tick: 38 | systick_set_clocksource(STK_CSR_CLKSOURCE_AHB); 39 | systick_set_reload(rcc_ahb_frequency / 10000); 40 | systick_interrupt_enable(); 41 | systick_counter_enable(); 42 | 43 | // clear counter so it starts right away 44 | STK_CVR = 0; 45 | 46 | // set prio 47 | nvic_set_priority(NVIC_SYSTICK_IRQ, NVIC_PRIO_SYSTICK); 48 | 49 | timeout_100us = 0; 50 | timeout2_100us = 0; 51 | timeout_100us_delay = 0; 52 | } 53 | 54 | void timeout_set_100us(__IO uint32_t hus) { 55 | timeout_100us = hus; 56 | } 57 | 58 | void timeout2_set_100us(__IO uint32_t hus) { 59 | timeout2_100us = hus; 60 | } 61 | 62 | uint8_t timeout_timed_out(void) { 63 | return(timeout_100us == 0); 64 | } 65 | 66 | uint8_t timeout2_timed_out(void) { 67 | return(timeout2_100us == 0); 68 | } 69 | 70 | void timeout2_delay_100us(uint16_t us) { 71 | timeout2_set_100us(us); 72 | while (!timeout2_timed_out()) {} 73 | } 74 | 75 | 76 | // seperate ms delay function 77 | void timeout_delay_ms(uint32_t timeout) { 78 | timeout_100us_delay = 10*timeout; 79 | 80 | while (timeout_100us_delay > 0) { 81 | } 82 | } 83 | 84 | void sys_tick_handler(void) { 85 | if (timeout_100us != 0) { 86 | timeout_100us--; 87 | } 88 | if (timeout2_100us != 0) { 89 | timeout2_100us--; 90 | } 91 | if (timeout_100us_delay != 0) { 92 | timeout_100us_delay--; 93 | } 94 | 95 | sound_handle_playback(); 96 | 97 | usb_handle_systick(); 98 | } 99 | 100 | uint32_t timeout_time_remaining(void) { 101 | return timeout_100us/ 10; 102 | } 103 | -------------------------------------------------------------------------------- /src/fonts/metric3x5.h: -------------------------------------------------------------------------------- 1 | #ifndef METRIC01_H 2 | #define METRIC01_H 3 | 4 | static uint8_t metric01[] = { 5 | 0x0, 0x0, // size of zero indicates fixed width font 6 | 3, // width 7 | 5, // height 8 | 32, // first char (space) 9 | 94, // char count 10 | 11 | 0x00, 0x00, 0x00, // space 12 | 0x0, 0x17, 0x0, // ! 13 | 0x3, 0x0, 0x3, // " 14 | 0xa, 0x1f, 0xa, // # 15 | 0x17, 0x1f, 0x1d, // $ 16 | 0x19, 0x4, 0x13, // % 17 | 0x1b, 0x1f, 0x14, // & 18 | 0x3, 0x0, 0x0, // ' 19 | 0xe, 0x11, 0x0, // ( 20 | 0x0, 0x11, 0xe, // ) 21 | 0x7, 0x5, 0x7, // * 22 | 0x4, 0xe, 0x4, // + 23 | 0x10, 0x8, 0x0, // , 24 | 0x4, 0x4, 0x4, // - 25 | 0x0, 0x10, 0x0, // . 26 | 0x18, 0x4, 0x3, // / 27 | 0x1f, 0x11, 0x1f, // 0 28 | 0x11, 0x1f, 0x10, // 1 29 | 0x1d, 0x15, 0x17, // 2 30 | 0x11, 0x15, 0x1f, // 3 31 | 0x7, 0x4, 0x1f, // 4 32 | 0x17, 0x15, 0x1d, // 5 33 | 0x1f, 0x15, 0x1d, // 6 34 | 0x1, 0x1, 0x1f, // 7 35 | 0x1f, 0x15, 0x1f, // 8 36 | 0x7, 0x5, 0x1f, // 9 37 | 0x0, 0x1b, 0x0, // : 38 | 0x10, 0xb, 0x0, // ; 39 | 0x4, 0xa, 0x11, // < 40 | 0xa, 0xa, 0xa, // = 41 | 0x11, 0xa, 0x4, // > 42 | 0x1, 0x15, 0x7, // ? 43 | 0x1f, 0x11, 0x17, // @ 44 | 0x1f, 0x5, 0x1f, // A 45 | 0x1f, 0x15, 0x1b, // B 46 | 0x1f, 0x11, 0x11, // C 47 | 0x1f, 0x11, 0xe, // D 48 | 0x1f, 0x15, 0x11, // E 49 | 0x1f, 0x5, 0x1, // F 50 | 0x1f, 0x11, 0x19, // G 51 | 0x1f, 0x4, 0x1f, // H 52 | 0x11, 0x1f, 0x11, // I 53 | 0x11, 0x11, 0xf, // J 54 | 0x1f, 0x4, 0x1b, // K 55 | 0x1f, 0x10, 0x10, // L 56 | 0x1f, 0x2, 0x1f, // M 57 | 0x1f, 0x1, 0x1f, // N 58 | 0x1f, 0x11, 0x1f, // O 59 | 0x1f, 0x5, 0x7, // P 60 | 0x1f, 0x19, 0x1f, // Q 61 | 0x1f, 0x5, 0x1b, // R 62 | 0x17, 0x15, 0x1d, // S 63 | 0x1, 0x1f, 0x1, // T 64 | 0x1f, 0x10, 0x1f, // U 65 | 0xf, 0x10, 0xf, // V 66 | 0x1f, 0x8, 0x1f, // W 67 | 0x1b, 0x4, 0x1b, // X 68 | 0x7, 0x14, 0x1f, // Y 69 | 0x19, 0x15, 0x13, // Z 70 | 0x1f, 0x11, 0x0, // [ 71 | 0x3, 0x4, 0x18, // `\` 72 | 0x0, 0x11, 0x1f, // ] 73 | 0x2, 0x1, 0x2, // ^ 74 | 0x10, 0x10, 0x10, // _ 75 | 0x1, 0x2, 0x0, // ` 76 | 0x1a, 0x1a, 0x1e, // a 77 | 0x1f, 0x14, 0x1c, // b 78 | 0x1c, 0x14, 0x14, // c 79 | 0x1c, 0x14, 0x1f, // d 80 | 0x1e, 0x16, 0x16, // e 81 | 0x4, 0x1f, 0x5, // f 82 | 0x16, 0x16, 0x1e, // g 83 | 0x1f, 0x4, 0x1c, // h 84 | 0x14, 0x1d, 0x10, // i 85 | 0x10, 0x10, 0xd, // j 86 | 0x1f, 0x8, 0x14, // k 87 | 0xf, 0x10, 0x10, // l 88 | 0x1c, 0x8, 0x1c, // m 89 | 0x1c, 0x4, 0x1c, // n 90 | 0x1c, 0x14, 0x1c, // o 91 | 0x1e, 0xa, 0xe, // p 92 | 0xe, 0xa, 0x1e, // q 93 | 0x1c, 0x4, 0x4, // r 94 | 0x17, 0x15, 0x1d, // s 95 | 0xf, 0x14, 0x14, // t 96 | 0x1c, 0x10, 0x1c, // u 97 | 0xc, 0x10, 0xc, // v 98 | 0x1c, 0x18, 0x1c, // w 99 | 0x14, 0x8, 0x14, // x 100 | 0x16, 0x14, 0x1e, // y 101 | 0x4, 0x1c, 0x10, // z 102 | 0x4, 0x1f, 0x11, // { 103 | 0x0, 0x1f, 0x0, // | 104 | 0x11, 0x1f, 0x4, // } 105 | 0x2, 0x6, 0x4 // ~ 106 | }; 107 | #endif 108 | 109 | -------------------------------------------------------------------------------- /src/lcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef LCD_H_ 21 | #define LCD_H_ 22 | 23 | #include 24 | #include 25 | #include "config.h" 26 | 27 | // the screen itself is 128 x 64 28 | #define LCD_WIDTH 128 29 | #define LCD_HEIGHT 64 30 | 31 | void lcd_init(void); 32 | void lcd_send_data(const uint8_t *buf); 33 | void lcd_powerdown(void); 34 | void lcd_show_logo(void); 35 | 36 | #define LCD_RW_HI() { gpio_set(LCD_RW_GPIO, LCD_RW_PIN); } 37 | #define LCD_RW_LO() { gpio_clear(LCD_RW_GPIO, LCD_RW_PIN); } 38 | 39 | #define LCD_RST_HI() { gpio_set(LCD_RST_GPIO, LCD_RST_PIN); } 40 | #define LCD_RST_LO() { gpio_clear(LCD_RST_GPIO, LCD_RST_PIN); } 41 | 42 | #define LCD_RS_HI() { gpio_set(LCD_RS_GPIO, LCD_RS_PIN); } 43 | #define LCD_RS_LO() { gpio_clear(LCD_RS_GPIO, LCD_RS_PIN); } 44 | 45 | #define LCD_RD_HI() { gpio_set(LCD_RD_GPIO, LCD_RD_PIN); } 46 | #define LCD_RD_LO() { gpio_clear(LCD_RD_GPIO, LCD_RD_PIN); } 47 | 48 | #define LCD_CS_HI() { gpio_set(LCD_CS_GPIO, LCD_CS_PIN); } 49 | #define LCD_CS_LO() { gpio_clear(LCD_CS_GPIO, LCD_CS_PIN); } 50 | 51 | // #define LCD_DATA_SET(data) { GPIO_ODR(LCD_DATA_GPIO) 52 | // = (GPIO_ODR(LCD_DATA_GPIO) & 0xFF00) | (data);} 53 | 54 | #define LCD_DATA_SET(data) {((uint8_t __IO*)&GPIO_ODR(LCD_DATA_GPIO))[0] = (data); } 55 | 56 | 57 | #define LCD_CMD_RESET 0xE2 58 | #define LCD_CMD_BIAS_1_9 0xA2 // 1/9 bias 59 | #define LCD_CMD_BIAS_1_7 0xA3 // 1/7 bias 60 | 61 | #define LCD_CMD_SEG_NORMAL 0xA0 62 | #define LCD_CMD_SEG_INVERSE 0xA1 63 | 64 | #define LCD_CMD_COM_NORMAL 0xC0 65 | #define LCD_CMD_COM_INVERSE 0xC8 66 | 67 | #define LCD_CMD_REG_RATIO_000 0x20 68 | #define LCD_CMD_REG_RATIO_001 0x21 69 | #define LCD_CMD_REG_RATIO_010 0x22 70 | #define LCD_CMD_REG_RATIO_011 0x23 71 | #define LCD_CMD_REG_RATIO_100 0x24 72 | #define LCD_CMD_REG_RATIO_101 0x25 73 | #define LCD_CMD_REG_RATIO_110 0x26 74 | #define LCD_CMD_REG_RATIO_111 0x27 75 | 76 | #define LCD_CMD_EV 0x81 77 | #define LCD_CMD_POWERCTRL_ALL_ON 0x2F 78 | 79 | #define LCD_CMD_SET_STARTLINE 0x40 80 | #define LCD_CMD_SET_PAGESTART 0xB0 81 | 82 | #define LCD_CMD_SET_COL_LO 0x00 83 | #define LCD_CMD_SET_COL_HI 0x10 84 | 85 | #define LCD_CMD_DISPLAY_OFF 0xAE 86 | #define LCD_CMD_DISPLAY_ON 0xAF 87 | 88 | #define LCD_CMD_MODE_RAM 0xA4 89 | #define LCD_CMD_MODE_ALLBLACK 0xA5 90 | 91 | 92 | #endif // LCD_H_ 93 | 94 | -------------------------------------------------------------------------------- /src/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | 21 | #include "io.h" 22 | #include "debug.h" 23 | #include "config.h" 24 | #include "console.h" 25 | #include "led.h" 26 | #include "delay.h" 27 | 28 | #include 29 | #include 30 | 31 | 32 | void io_init(void) { 33 | debug("io: init\n"); debug_flush(); 34 | io_init_gpio(); 35 | } 36 | 37 | void io_init_gpio(void) { 38 | // enable clocks 39 | rcc_periph_clock_enable(GPIO_RCC(POWERDOWN_GPIO)); 40 | rcc_periph_clock_enable(GPIO_RCC(BUTTON_POWER_BOTH_GPIO)); 41 | 42 | // set high: 43 | gpio_set(POWERDOWN_GPIO, POWERDOWN_PIN); 44 | 45 | // set powerdown trigger pin as output 46 | gpio_mode_setup(POWERDOWN_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, POWERDOWN_PIN); 47 | gpio_set_output_options(POWERDOWN_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, POWERDOWN_PIN); 48 | 49 | // set buttons as input: 50 | gpio_mode_setup(BUTTON_POWER_BOTH_GPIO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, BUTTON_POWER_BOTH_PIN); 51 | gpio_set_output_options(BUTTON_POWER_BOTH_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, BUTTON_POWER_BOTH_PIN); 52 | } 53 | 54 | 55 | void io_test_prepare(void) { 56 | // set all ios to input 57 | gpio_mode_setup(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 58 | gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 59 | gpio_mode_setup(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 60 | gpio_mode_setup(GPIOD, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 61 | gpio_mode_setup(GPIOE, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 62 | gpio_mode_setup(GPIOF, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, 0xFFFF); 63 | } 64 | 65 | uint32_t io_powerbutton_pressed(void) { 66 | return(gpio_get(BUTTON_POWER_BOTH_GPIO, BUTTON_POWER_BOTH_PIN) == 0); 67 | } 68 | 69 | // show status of all gpios on screen 70 | void io_test(void) { 71 | uint32_t i, p; 72 | 73 | while (1) { 74 | console_clear(); 75 | debug("GPIO TEST\n\n"); 76 | debug(" FEDCBA9876543210\n"); 77 | for (p = 0; p < 6; p++) { 78 | debug("GPIO"); 79 | debug_putc('A'+p); 80 | debug(" "); 81 | for (i = 0; i < 16; i++) { 82 | if (gpio_get((GPIO_PORT_A_BASE + p*0x00000400), (1 << (15-i)))) { 83 | debug_putc('1'); 84 | } else { 85 | debug_putc('0'); 86 | } 87 | } 88 | debug_put_newline(); 89 | } 90 | debug_flush(); 91 | delay_ms(50); 92 | } 93 | } 94 | 95 | void io_powerdown(void) { 96 | gpio_clear(POWERDOWN_GPIO, POWERDOWN_PIN); 97 | 98 | // system is powered off now... 99 | while (1) { } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /device/stm32f0xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/GPIO_IOToggle/stm32f0xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 24-July-2014 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F0XX_CONF_H 30 | #define __STM32F0XX_CONF_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Comment the line below to disable peripheral header file inclusion */ 34 | #include "stm32f0xx_adc.h" 35 | #include "stm32f0xx_can.h" 36 | #include "stm32f0xx_cec.h" 37 | #include "stm32f0xx_comp.h" 38 | #include "stm32f0xx_crc.h" 39 | #include "stm32f0xx_crs.h" 40 | #include "stm32f0xx_dac.h" 41 | #include "stm32f0xx_dbgmcu.h" 42 | #include "stm32f0xx_dma.h" 43 | #include "stm32f0xx_exti.h" 44 | #include "stm32f0xx_flash.h" 45 | #include "stm32f0xx_gpio.h" 46 | #include "stm32f0xx_i2c.h" 47 | #include "stm32f0xx_iwdg.h" 48 | #include "stm32f0xx_pwr.h" 49 | #include "stm32f0xx_rcc.h" 50 | #include "stm32f0xx_rtc.h" 51 | #include "stm32f0xx_spi.h" 52 | #include "stm32f0xx_syscfg.h" 53 | #include "stm32f0xx_tim.h" 54 | #include "stm32f0xx_usart.h" 55 | #include "stm32f0xx_wwdg.h" 56 | #include "stm32f0xx_misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 57 | 58 | /* Exported types ------------------------------------------------------------*/ 59 | /* Exported constants --------------------------------------------------------*/ 60 | /* Uncomment the line below to expanse the "assert_param" macro in the 61 | Standard Peripheral Library drivers code */ 62 | /* #define USE_FULL_ASSERT 1 */ 63 | 64 | /* Exported macro ------------------------------------------------------------*/ 65 | #ifdef USE_FULL_ASSERT 66 | 67 | /** 68 | * @brief The assert_param macro is used for function's parameters check. 69 | * @param expr: If expr is false, it calls assert_failed function which reports 70 | * the name of the source file and the source line number of the call 71 | * that failed. If expr is true, it returns no value. 72 | * @retval None 73 | */ 74 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 75 | /* Exported functions ------------------------------------------------------- */ 76 | void assert_failed(uint8_t* file, uint32_t line); 77 | #else 78 | #define assert_param(expr) ((void)0) 79 | #endif /* USE_FULL_ASSERT */ 80 | 81 | #endif /* __STM32F0XX_CONF_H */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /src/touch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef TOUCH_H_ 21 | #define TOUCH_H_ 22 | 23 | #include 24 | 25 | #include "config.h" 26 | 27 | void touch_init(void); 28 | void touch_test(void); 29 | 30 | 31 | typedef struct { 32 | uint8_t event_id; 33 | uint16_t x; 34 | uint16_t y; 35 | } touch_event_t; 36 | 37 | touch_event_t touch_get_and_clear_last_event(void); 38 | 39 | // void EXTI4_15_IRQHandler(void); 40 | 41 | #define TOUCH_FT6236_MAX_TOUCH_POINTS 2 42 | 43 | #define TOUCH_FT6236_REG_TH_GROUP 0x80 44 | #define TOUCH_FT6236_REG_PERIODACTIVE 0x88 45 | #define TOUCH_FT6236_REG_LIB_VER_H 0xa1 46 | #define TOUCH_FT6236_REG_LIB_VER_L 0xa2 47 | #define TOUCH_FT6236_REG_CIPHER 0xa3 48 | #define TOUCH_FT6236_REG_FIRMID 0xa6 49 | #define TOUCH_FT6236_REG_FOCALTECH_ID 0xa8 50 | #define TOUCH_FT6236_REG_RELEASE_CODE_ID 0xaf 51 | 52 | #define TOUCH_FT6236_EVENT_PRESS_DOWN 0 53 | #define TOUCH_FT6236_EVENT_LIFT_UP 1 54 | #define TOUCH_FT6236_EVENT_CONTACT 2 55 | #define TOUCH_FT6236_EVENT_NO_EVENT 3 56 | 57 | #define TOUCH_RESET_HI() { gpio_set(TOUCH_RESET_GPIO, TOUCH_RESET_PIN); } 58 | #define TOUCH_RESET_LO() { gpio_clear(TOUCH_RESET_GPIO, TOUCH_RESET_PIN); } 59 | 60 | #define TOUCH_FT6236_GESTURE_MOVE_FLAG 0x10 61 | #define TOUCH_FT6236_GESTURE_MOVE_UP 0x10 62 | #define TOUCH_FT6236_GESTURE_MOVE_RIGHT 0x14 63 | #define TOUCH_FT6236_GESTURE_MOVE_DOWN 0x18 64 | #define TOUCH_FT6236_GESTURE_MOVE_LEFT 0x1C 65 | #define TOUCH_FT6236_GESTURE_ZOOM_IN 0x48 66 | #define TOUCH_FT6236_GESTURE_ZOOM_OUT 0x49 67 | #define TOUCH_FT6236_GESTURE_NONE 0x00 68 | 69 | #define TOUCH_GESTURE_UP ((TOUCH_FT6236_GESTURE_MOVE_UP & 0x0F)+1) 70 | #define TOUCH_GESTURE_DOWN ((TOUCH_FT6236_GESTURE_MOVE_DOWN & 0x0F)+1) 71 | #define TOUCH_GESTURE_LEFT ((TOUCH_FT6236_GESTURE_MOVE_LEFT & 0x0F)+1) 72 | #define TOUCH_GESTURE_RIGHT ((TOUCH_FT6236_GESTURE_MOVE_RIGHT & 0x0F)+1) 73 | #define TOUCH_GESTURE_MOUSE_DOWN (0x80+TOUCH_FT6236_EVENT_PRESS_DOWN) 74 | #define TOUCH_GESTURE_MOUSE_UP (0x80+TOUCH_FT6236_EVENT_LIFT_UP) 75 | #define TOUCH_GESTURE_MOUSE_MOVE (0x80+TOUCH_FT6236_EVENT_CONTACT) 76 | #define TOUCH_GESTURE_MOUSE_NONE (0x80+TOUCH_FT6236_EVENT_NO_EVENT) 77 | 78 | #define I2C_CR2_FREQ_MASK 0x3ff 79 | #define I2C_CCR_CCRMASK 0xfff 80 | #define I2C_TRISE_MASK 0x3f 81 | 82 | struct __attribute__((__packed__)) touch_ft6236_touchpoint { 83 | union { 84 | uint8_t xhi; 85 | uint8_t event; 86 | }; 87 | 88 | uint8_t xlo; 89 | 90 | union { 91 | uint8_t yhi; 92 | uint8_t id; 93 | }; 94 | 95 | uint8_t ylo; 96 | uint8_t weight; 97 | uint8_t misc; 98 | }; 99 | 100 | // this packet represents the register map as read from offset 0 101 | typedef struct __attribute__((__packed__)) { 102 | uint8_t dev_mode; 103 | uint8_t gest_id; 104 | uint8_t touches; 105 | struct touch_ft6236_touchpoint points[TOUCH_FT6236_MAX_TOUCH_POINTS]; 106 | } touch_ft6236_packet_t; 107 | 108 | touch_event_t touch_get_last_event(void); 109 | 110 | #endif // TOUCH_H_ 111 | -------------------------------------------------------------------------------- /peripheral_lib/inc/stm32f0xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file contains all the functions prototypes for the WWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F0XX_WWDG_H 31 | #define __STM32F0XX_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f0xx.h" 39 | 40 | /** @addtogroup STM32F0xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /* Exported macro ------------------------------------------------------------*/ 78 | /* Exported functions ------------------------------------------------------- */ 79 | /* Function used to set the WWDG configuration to the default reset state ****/ 80 | void WWDG_DeInit(void); 81 | 82 | /* Prescaler, Refresh window and Counter configuration functions **************/ 83 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 84 | void WWDG_SetWindowValue(uint8_t WindowValue); 85 | void WWDG_EnableIT(void); 86 | void WWDG_SetCounter(uint8_t Counter); 87 | 88 | /* WWDG activation functions **************************************************/ 89 | void WWDG_Enable(uint8_t Counter); 90 | 91 | /* Interrupts and flags management functions **********************************/ 92 | FlagStatus WWDG_GetFlagStatus(void); 93 | void WWDG_ClearFlag(void); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* __STM32F0XX_WWDG_H */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /src/console.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "console.h" 21 | #include "screen.h" 22 | #include "font.h" 23 | #include "delay.h" 24 | 25 | static char console_buffer[CONSOLE_BUFFER_SIZE_Y][CONSOLE_BUFFER_SIZE_X+1]; 26 | static uint8_t console_write_x; 27 | static uint8_t console_write_y; 28 | 29 | void console_init(void) { 30 | // initialise console 31 | console_clear(); 32 | } 33 | 34 | void console_clear(void) { 35 | uint32_t x, y; 36 | 37 | console_write_x = 0; 38 | console_write_y = 0; 39 | for (y = 0; y < CONSOLE_BUFFER_SIZE_Y; y++) { 40 | for (x = 0; x < CONSOLE_BUFFER_SIZE_X; x++) { 41 | console_buffer[y][x] = 0; 42 | } 43 | } 44 | } 45 | 46 | static void console_render_str(uint8_t line, uint8_t color, char *str) { 47 | uint32_t h; 48 | 49 | screen_set_font(CONSOLE_FONT, &h, 0); 50 | 51 | // write string to screen at position x,y 52 | uint8_t height = h + 1; 53 | 54 | #if (CONSOLE_FONT_HEIGHT == 5) 55 | // center image for 5px height font TODO: make this universal 56 | uint8_t y = (height) * line + 2; 57 | #else 58 | uint8_t y = (height) * line + 0; 59 | #endif // (CONSOLE_FONT_HEIGHT == 5) 60 | 61 | // render to screen buffer 62 | screen_puts_xy(1, y, color, str); 63 | } 64 | 65 | 66 | void console_puts(char *str) { 67 | while (*str) { 68 | console_putc(*str); 69 | } 70 | } 71 | 72 | void console_putc(char c) { 73 | uint32_t x = 0; 74 | // print one char to our screen, this function 75 | // handles the screen layout etc 76 | 77 | if (c == '\r') { 78 | // reset x pointer 79 | console_write_x = 0; 80 | return; 81 | } 82 | 83 | if (c == '\n') { 84 | // newline, this will trigger a skip to next line 85 | console_write_x = 100; 86 | } else { 87 | // output char: 88 | console_buffer[console_write_y][console_write_x] = c; 89 | } 90 | 91 | // keep track of lines 92 | console_write_x++; 93 | if (console_write_x >= (CONSOLE_BUFFER_SIZE_X)) { 94 | // switch and clear next line 95 | console_write_y = (console_write_y + 1) % CONSOLE_BUFFER_SIZE_Y; 96 | for (x = 0; x < CONSOLE_BUFFER_SIZE_X; x++) { 97 | console_buffer[console_write_y][x] = 0; 98 | } 99 | console_write_x = 0; 100 | } 101 | } 102 | 103 | void console_render(void) { 104 | uint32_t i; 105 | uint8_t color = CONSOLE_TEXTCOLOR; 106 | 107 | // fill screen with inverse of color 108 | screen_fill(1-color); 109 | 110 | // update screen memory to show the current line buffer 111 | // we want the current line to be at the bottom, calculate first line to render: 112 | uint8_t line_now = console_write_y; 113 | if (console_buffer[line_now][0] != 0) { 114 | line_now++; 115 | } 116 | 117 | // calculate first line to print: 118 | uint8_t line = (line_now+1) % CONSOLE_BUFFER_SIZE_Y; 119 | for (i = 0; i < CONSOLE_BUFFER_SIZE_Y-1; i++) { 120 | // print current line 121 | console_render_str(i, color, console_buffer[line]); 122 | // fetch next line id 123 | line = (line + 1) % CONSOLE_BUFFER_SIZE_Y; 124 | } 125 | } 126 | 127 | 128 | -------------------------------------------------------------------------------- /pcb/openground_cc2500.net: -------------------------------------------------------------------------------- 1 | (export (version D) 2 | (design 3 | (source /home/ss/src/OpenGround/pcb/openground_cc2500.sch) 4 | (date "Wed 05 Oct 2000 00:17:33 AM CEST") 5 | (tool "eeschema (2013-jul-07)-stable")) 6 | (components 7 | (comp (ref U1) 8 | (value FS-I6S_FOOTPRINT) 9 | (libsource (lib custom) (part FS-I6S_FOOTPRINT)) 10 | (sheetpath (names /) (tstamps /)) 11 | (tstamp 57F4E071)) 12 | (comp (ref U2) 13 | (value CC2500_FOOTPRINT) 14 | (libsource (lib custom) (part CC2500_FOOTPRINT)) 15 | (sheetpath (names /) (tstamps /)) 16 | (tstamp 57F4E080))) 17 | (libparts 18 | (libpart (lib custom) (part CC2500_FOOTPRINT) 19 | (fields 20 | (field (name Reference) U) 21 | (field (name Value) CC2500_FOOTPRINT)) 22 | (pins 23 | (pin (num 1) (name vcc) (type input)) 24 | (pin (num 2) (name SI) (type input)) 25 | (pin (num 3) (name SCLK) (type input)) 26 | (pin (num 4) (name SO) (type input)) 27 | (pin (num 5) (name GDO2) (type input)) 28 | (pin (num 6) (name GND) (type input)) 29 | (pin (num 7) (name GDO0) (type input)) 30 | (pin (num 8) (name CSn) (type input)) 31 | (pin (num 9) (name PA_EN) (type input)) 32 | (pin (num 10) (name LNA_EN) (type input)) 33 | (pin (num 11) (name MOUNT_A) (type input)))) 34 | (libpart (lib custom) (part FS-I6S_FOOTPRINT) 35 | (fields 36 | (field (name Reference) U) 37 | (field (name Value) FS-I6S_FOOTPRINT)) 38 | (pins 39 | (pin (num 1) (name SDIO) (type input)) 40 | (pin (num 2) (name SCK) (type input)) 41 | (pin (num 3) (name SCS) (type input)) 42 | (pin (num 4) (name GND) (type input)) 43 | (pin (num 5) (name RF1) (type input)) 44 | (pin (num 6) (name RFC) (type input)) 45 | (pin (num 7) (name GND) (type input)) 46 | (pin (num 8) (name ANT1) (type input)) 47 | (pin (num 9) (name GND) (type input)) 48 | (pin (num 10) (name GND) (type input)) 49 | (pin (num 11) (name ANT2) (type input)) 50 | (pin (num 12) (name GND) (type input)) 51 | (pin (num 13) (name RX/W) (type input)) 52 | (pin (num 14) (name TX/W) (type input)) 53 | (pin (num 15) (name GIO2) (type input)) 54 | (pin (num 16) (name GIO1) (type input)) 55 | (pin (num 17) (name GND) (type input)) 56 | (pin (num 18) (name 3V3) (type input))))) 57 | (libraries 58 | (library (logical custom) 59 | (uri custom.lib))) 60 | (nets 61 | (net (code 1) (name "") 62 | (node (ref U2) (pin 8)) 63 | (node (ref U1) (pin 3))) 64 | (net (code 2) (name "") 65 | (node (ref U2) (pin 7)) 66 | (node (ref U1) (pin 5))) 67 | (net (code 3) (name "") 68 | (node (ref U2) (pin 5)) 69 | (node (ref U1) (pin 15))) 70 | (net (code 4) (name "") 71 | (node (ref U2) (pin 4)) 72 | (node (ref U1) (pin 16))) 73 | (net (code 5) (name "") 74 | (node (ref U2) (pin 3)) 75 | (node (ref U1) (pin 2))) 76 | (net (code 6) (name GND) 77 | (node (ref U1) (pin 17)) 78 | (node (ref U2) (pin 6)) 79 | (node (ref U2) (pin 11)) 80 | (node (ref U1) (pin 4))) 81 | (net (code 7) (name "") 82 | (node (ref U2) (pin 10)) 83 | (node (ref U1) (pin 14))) 84 | (net (code 8) (name "") 85 | (node (ref U1) (pin 13)) 86 | (node (ref U2) (pin 9))) 87 | (net (code 9) (name "") 88 | (node (ref U1) (pin 7))) 89 | (net (code 10) (name "") 90 | (node (ref U1) (pin 9))) 91 | (net (code 11) (name "") 92 | (node (ref U1) (pin 10))) 93 | (net (code 12) (name "") 94 | (node (ref U1) (pin 12))) 95 | (net (code 13) (name "") 96 | (node (ref U1) (pin 18)) 97 | (node (ref U2) (pin 1))) 98 | (net (code 14) (name "") 99 | (node (ref U1) (pin 11))) 100 | (net (code 15) (name "") 101 | (node (ref U1) (pin 8))) 102 | (net (code 16) (name "") 103 | (node (ref U1) (pin 6))) 104 | (net (code 17) (name "") 105 | (node (ref U1) (pin 1)) 106 | (node (ref U2) (pin 2))))) 107 | -------------------------------------------------------------------------------- /src/eeprom_emulation/st_eeprom.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file STM32F0xx_EEPROM_Emulation/inc/eeprom.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 29-May-2012 7 | * @brief This file contains all the functions prototypes for the EEPROM 8 | * emulation firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2012 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef ST_EEPROM_H__ 31 | #define ST_EEPROM_H__ 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include 35 | // import variables from linker: 36 | extern long _emulated_eeprom; 37 | extern long _emulated_eeprom_page_size; 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* Define the size of the sectors to be used */ 41 | #define EEPROM_PAGE_SIZE ((uint32_t)0x800) /* Page size = 2KByte */ 42 | 43 | /* EEPROM start address in Flash */ 44 | #define EEPROM_START_ADDRESS ((uint32_t)0x08000000+128*1024-2*EEPROM_PAGE_SIZE) 45 | // EEPROM emulation start address: 46 | // #define EEPROM_START_ADDRESS ((uint32_t)0x0801F000) 47 | // EEPROM emulation start address: from sector2, after 8KByte of used Flash memory 48 | 49 | /* Pages 0 and 1 base and end addresses */ 50 | #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000)) 51 | #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (EEPROM_PAGE_SIZE - 1))) 52 | 53 | #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + EEPROM_PAGE_SIZE)) 54 | #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * EEPROM_PAGE_SIZE - 1))) 55 | 56 | /* Used Flash pages for EEPROM emulation */ 57 | #define PAGE0 ((uint16_t)0x0000) 58 | #define PAGE1 ((uint16_t)0x0001) 59 | 60 | /* No valid page define */ 61 | #define NO_VALID_PAGE ((uint16_t)0x00AB) 62 | 63 | /* Page status definitions */ 64 | #define ERASED ((uint16_t)0xFFFF) /* Page is empty */ 65 | #define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */ 66 | #define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */ 67 | 68 | /* Valid pages in read and write defines */ 69 | #define READ_FROM_VALID_PAGE ((uint8_t)0x00) 70 | #define WRITE_IN_VALID_PAGE ((uint8_t)0x01) 71 | 72 | /* Page full define */ 73 | #define PAGE_FULL ((uint8_t)0x80) 74 | 75 | 76 | typedef enum 77 | { 78 | FLASH_BUSY = 1, 79 | FLASH_ERROR_WRP, 80 | FLASH_ERROR_PROGRAM, 81 | FLASH_COMPLETE, 82 | FLASH_TIMEOUT 83 | }FLASH_Status; 84 | 85 | /* Variables' number */ 86 | //#define NB_OF_VAR ((uint8_t)0x03) 87 | 88 | /* Exported types ------------------------------------------------------------*/ 89 | /* Exported macro ------------------------------------------------------------*/ 90 | /* Exported functions ------------------------------------------------------- */ 91 | uint16_t EE_Init(void); 92 | uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data); 93 | uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data); 94 | 95 | #endif // ST_EEPROM_H__ 96 | 97 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 98 | -------------------------------------------------------------------------------- /src/screen.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef SCREEN_H_ 21 | #define SCREEN_H_ 22 | 23 | #include 24 | 25 | #include "config.h" 26 | #include "lcd.h" 27 | 28 | #define SCREEN_BUFFER_SIZE ((LCD_WIDTH * LCD_HEIGHT) / 8) 29 | // extern static uint8_t screen_buffer[SCREEN_BUFFER_SIZE]; 30 | 31 | void screen_init(void); 32 | void screen_clear(void); 33 | void screen_update(void); 34 | void screen_test(void); 35 | 36 | void screen_fill_round_rect(uint8_t x, uint8_t y, uint8_t width, \ 37 | uint8_t height, uint8_t radius, uint8_t color); 38 | void screen_fill_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color); 39 | void screen_draw_round_rect(uint8_t x, uint8_t y, uint8_t width, \ 40 | uint8_t height, uint8_t radius, uint8_t color); 41 | void screen_draw_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color); 42 | void screen_draw_hline(uint8_t x, uint8_t y, uint8_t width, uint8_t color); 43 | // void screen_draw_round_rect(uint8_t x, uint8_t y, uint8_t width, 44 | // uint8_t height, uint8_t radius, uint8_t color); 45 | // void screen_draw_rect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color); 46 | // void screen_draw_hline(uint8_t x, uint8_t y, uint8_t width, uint8_t color); 47 | void screen_draw_vline(uint8_t x, uint8_t y, uint8_t height, uint8_t color); 48 | void screen_set_pixels(uint8_t x, uint8_t y, uint8_t x2, uint8_t y2, uint8_t color); 49 | void screen_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color); 50 | 51 | 52 | uint8_t screen_put_char(char c); 53 | uint32_t screen_strlen(char *str); 54 | void screen_set_font(const uint8_t *font, uint32_t *h, uint32_t *w); 55 | void screen_puts_xy(uint8_t x, uint8_t y, uint8_t color, char *str); 56 | void screen_puts_xy_centered(uint8_t y, uint8_t x, uint8_t color, char *str); 57 | void screen_puts_centered(uint8_t y, uint8_t color, char *str); 58 | void screen_put_int8(uint8_t x, uint8_t y, uint8_t color, int8_t c); 59 | void screen_put_uint8(uint8_t x, uint8_t y, uint8_t color, uint8_t c); 60 | void screen_put_uint8_2dec(uint8_t x, uint8_t y, uint8_t color, uint8_t c); 61 | void screen_put_uint8_1dec(uint8_t x, uint8_t y, uint8_t color, uint8_t c); 62 | void screen_put_time(uint8_t x, uint8_t y, uint8_t color, int16_t time); 63 | void screen_put_fixed2_1digit(uint8_t x, uint8_t y, uint8_t color, uint32_t v); 64 | void screen_put_uint14(uint8_t x, uint8_t y, uint8_t color, uint16_t c); 65 | void screen_put_hex16(uint8_t x, uint8_t y, uint8_t color, uint16_t val); 66 | void screen_put_hex8(uint8_t x, uint8_t y, uint8_t color, uint8_t val); 67 | void screen_put_fixed2(uint8_t x, uint8_t y, uint8_t color, uint16_t c); 68 | void screen_fill(uint8_t color); 69 | 70 | #define screen_buffer_read(_addr) (screen_buffer[_addr]) 71 | #define screen_buffer_write(_addr, _val) {\ 72 | if (_addr >= SCREEN_BUFFER_SIZE) { \ 73 | /*Serial.write("ERROR: "); Serial.print(_addr); Serial.write("\r\n");*/ \ 74 | } else { \ 75 | screen_buffer[_addr] = (uint8_t)_val; \ 76 | } \ 77 | } 78 | 79 | #define _screen_absDiff(x, y) (((x) > (y)) ? ((x)-(y)) : ((y)-(x))) 80 | #define _screen_swap(a, b) {uint8_t t; t = (a); a = (b); b = t;} 81 | 82 | #define screen_set_dot(x, y, color) { \ 83 | if (((x) >= LCD_WIDTH) || ((y) >= LCD_HEIGHT)) { return; } \ 84 | if (color) { \ 85 | screen_buffer[((y)/8)*128 + (x)] |= (1 << ((y) % 8)); \ 86 | } else { \ 87 | screen_buffer[((y)/8)*128 + (x)] &= ~(1 << ((y) % 8)); \ 88 | } \ 89 | } 90 | 91 | #endif // SCREEN_H_ 92 | 93 | -------------------------------------------------------------------------------- /src/fonts/tomthumb3x5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * based on TomThumb 3 | * http://robey.lag.net/2010/01/23/tiny-monospace-font.html 4 | * 5 | * I converted this to a fixed width 3x5 font 6 | */ 7 | #ifndef __FONT_TOMTHUMB3x5__ 8 | #define __FONT_TOMTHUMB3x5__ 9 | 10 | #include 11 | 12 | const uint8_t font_tomthumb3x5 [] = { 13 | 0x00, 0x00, // fixed width font 14 | 3, //width 3px 15 | 5, //heigh 5px 16 | 0x20, // first char 17 | 0x60, // char count 18 | 19 | // font data 20 | 0x00>>2, 0x00>>2, 0x00>>2, // 32 21 | 0x00>>2, 0x5C>>2, 0x00>>2, // 33 22 | 0x0C>>2, 0x00>>2, 0x0C>>2, // 34 23 | 0x7C>>2, 0x28>>2, 0x7C>>2, // 35 24 | 0x28>>2, 0x7C>>2, 0x14>>2, // 36 25 | 0x24>>2, 0x10>>2, 0x48>>2, // 37 26 | 0x3C>>2, 0x5C>>2, 0x70>>2, // 38 27 | 0x00>>2, 0x0C>>2, 0x00>>2, // 39 28 | 0x00>>2, 0x38>>2, 0x44>>2, // 40 29 | 0x44>>2, 0x38>>2, 0x00>>2, // 41 30 | 0x14>>2, 0x08>>2, 0x14>>2, // 42 31 | 0x10>>2, 0x38>>2, 0x10>>2, // 43 32 | 0x00>>2, 0x40>>2, 0x20>>2, // 44 33 | 0x10>>2, 0x10>>2, 0x10>>2, // 45 34 | 0x00>>2, 0x40>>2, 0x00>>2, // 46 35 | 0x60>>2, 0x10>>2, 0x0C>>2, // 47 36 | 0x78>>2, 0x44>>2, 0x3C>>2, // 48 37 | 0x00>>2, 0x08>>2, 0x7C>>2, // 49 38 | 0x64>>2, 0x54>>2, 0x48>>2, // 50 39 | 0x44>>2, 0x54>>2, 0x28>>2, // 51 40 | 0x1C>>2, 0x10>>2, 0x7C>>2, // 52 41 | 0x5C>>2, 0x54>>2, 0x24>>2, // 53 42 | 0x78>>2, 0x54>>2, 0x74>>2, // 54 43 | 0x64>>2, 0x14>>2, 0x0C>>2, // 55 44 | 0x7C>>2, 0x54>>2, 0x7C>>2, // 56 45 | 0x5C>>2, 0x54>>2, 0x3C>>2, // 57 46 | 0x00>>2, 0x28>>2, 0x00>>2, // 58 47 | 0x40>>2, 0x28>>2, 0x00>>2, // 59 48 | 0x10>>2, 0x28>>2, 0x44>>2, // 60 49 | 0x28>>2, 0x28>>2, 0x28>>2, // 61 50 | 0x44>>2, 0x28>>2, 0x10>>2, // 62 51 | 0x04>>2, 0x54>>2, 0x0C>>2, // 63 52 | 0x38>>2, 0x54>>2, 0x58>>2, // 64 53 | 0x78>>2, 0x14>>2, 0x78>>2, // 65 54 | 0x7C>>2, 0x54>>2, 0x28>>2, // 66 55 | 0x38>>2, 0x44>>2, 0x44>>2, // 67 56 | 0x7C>>2, 0x44>>2, 0x38>>2, // 68 57 | 0x7C>>2, 0x54>>2, 0x54>>2, // 69 58 | 0x7C>>2, 0x14>>2, 0x14>>2, // 70 59 | 0x38>>2, 0x54>>2, 0x74>>2, // 71 60 | 0x7C>>2, 0x10>>2, 0x7C>>2, // 72 61 | 0x44>>2, 0x7C>>2, 0x44>>2, // 73 62 | 0x20>>2, 0x40>>2, 0x3C>>2, // 74 63 | 0x7C>>2, 0x10>>2, 0x6C>>2, // 75 64 | 0x7C>>2, 0x40>>2, 0x40>>2, // 76 65 | 0x7C>>2, 0x18>>2, 0x7C>>2, // 77 66 | 0x7C>>2, 0x38>>2, 0x7C>>2, // 78 67 | 0x38>>2, 0x44>>2, 0x38>>2, // 79 68 | 0x7C>>2, 0x14>>2, 0x08>>2, // 80 69 | 0x38>>2, 0x64>>2, 0x78>>2, // 81 70 | 0x7C>>2, 0x34>>2, 0x58>>2, // 82 71 | 0x48>>2, 0x54>>2, 0x24>>2, // 83 72 | 0x04>>2, 0x7C>>2, 0x04>>2, // 84 73 | 0x3C>>2, 0x40>>2, 0x7C>>2, // 85 74 | 0x1C>>2, 0x60>>2, 0x1C>>2, // 86 75 | 0x7C>>2, 0x30>>2, 0x7C>>2, // 87 76 | 0x6C>>2, 0x10>>2, 0x6C>>2, // 88 77 | 0x0C>>2, 0x70>>2, 0x0C>>2, // 89 78 | 0x64>>2, 0x54>>2, 0x4C>>2, // 90 79 | 0x7C>>2, 0x44>>2, 0x44>>2, // 91 80 | 0x08>>2, 0x10>>2, 0x20>>2, // 92 81 | 0x44>>2, 0x44>>2, 0x7C>>2, // 93 82 | 0x08>>2, 0x04>>2, 0x08>>2, // 94 83 | 0x40>>2, 0x40>>2, 0x40>>2, // 95 84 | 0x00>>2, 0x04>>2, 0x08>>2, // 96 85 | 0x68>>2, 0x58>>2, 0x70>>2, // 97 86 | 0x7C>>2, 0x48>>2, 0x30>>2, // 98 87 | 0x30>>2, 0x48>>2, 0x48>>2, // 99 88 | 0x30>>2, 0x48>>2, 0x7C>>2, // 100 89 | 0x30>>2, 0x68>>2, 0x58>>2, // 101 90 | 0x10>>2, 0x78>>2, 0x14>>2, // 102 91 | 0x30>>2, 0xA8>>2, 0x78>>2, // 103 92 | 0x7C>>2, 0x08>>2, 0x70>>2, // 104 93 | 0x00>>2, 0x74>>2, 0x00>>2, // 105 94 | 0x40>>2, 0x80>>2, 0x74>>2, // 106 95 | 0x7C>>2, 0x30>>2, 0x48>>2, // 107 96 | 0x44>>2, 0x7C>>2, 0x40>>2, // 108 97 | 0x78>>2, 0x38>>2, 0x78>>2, // 109 98 | 0x78>>2, 0x08>>2, 0x70>>2, // 110 99 | 0x30>>2, 0x48>>2, 0x30>>2, // 111 100 | 0xF8>>2, 0x48>>2, 0x30>>2, // 112 101 | 0x30>>2, 0x48>>2, 0xF8>>2, // 113 102 | 0x70>>2, 0x08>>2, 0x08>>2, // 114 103 | 0x50>>2, 0x78>>2, 0x28>>2, // 115 104 | 0x08>>2, 0x7C>>2, 0x48>>2, // 116 105 | 0x38>>2, 0x40>>2, 0x78>>2, // 117 106 | 0x38>>2, 0x60>>2, 0x38>>2, // 118 107 | 0x78>>2, 0x70>>2, 0x78>>2, // 119 108 | 0x48>>2, 0x30>>2, 0x48>>2, // 120 109 | 0x18>>2, 0xA0>>2, 0x78>>2, // 121 110 | 0x68>>2, 0x78>>2, 0x58>>2, // 122 111 | 0x10>>2, 0x6C>>2, 0x44>>2, // 123 112 | 0x00>>2, 0x6C>>2, 0x00>>2, // 124 113 | 0x44>>2, 0x6C>>2, 0x10>>2, // 125 114 | 0x08>>2, 0x0C>>2, 0x04>>2, // 126 115 | 116 | }; 117 | 118 | #endif 119 | 120 | -------------------------------------------------------------------------------- /src/fonts/system5x7.h: -------------------------------------------------------------------------------- 1 | /* 2 | * based on the openglcd system 5x7 font 3 | */ 4 | #ifndef __FONT_SYSTEM5x7_H__ 5 | #define __FONT_SYSTEM5x7_H__ 6 | 7 | #include 8 | 9 | const uint8_t font_system5x7 [] = { 10 | 0x0, 0x0, // size of zero indicates fixed width font, 11 | 5, // width 12 | 7, // height 13 | 0x20, // first char 14 | 0x61, // char count 15 | 16 | // Fixed width; char width table not used 17 | 18 | // font data 19 | 0x00, 0x00, 0x00, 0x00, 0x00,// (space) 20 | 0x00, 0x00, 0x5F, 0x00, 0x00,// ! 21 | 0x00, 0x07, 0x00, 0x07, 0x00,// " 22 | 0x14, 0x7F, 0x14, 0x7F, 0x14,// # 23 | 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $ 24 | 0x23, 0x13, 0x08, 0x64, 0x62,// % 25 | 0x36, 0x49, 0x55, 0x22, 0x50,// & 26 | 0x00, 0x05, 0x03, 0x00, 0x00,// ' 27 | 0x00, 0x1C, 0x22, 0x41, 0x00,// ( 28 | 0x00, 0x41, 0x22, 0x1C, 0x00,// ) 29 | 0x08, 0x2A, 0x1C, 0x2A, 0x08,// * 30 | 0x08, 0x08, 0x3E, 0x08, 0x08,// + 31 | 0x00, 0x50, 0x30, 0x00, 0x00,// , 32 | 0x08, 0x08, 0x08, 0x08, 0x08,// - 33 | 0x00, 0x60, 0x60, 0x00, 0x00,// . 34 | 0x20, 0x10, 0x08, 0x04, 0x02,// / 35 | 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0 36 | 0x00, 0x42, 0x7F, 0x40, 0x00,// 1 37 | 0x42, 0x61, 0x51, 0x49, 0x46,// 2 38 | 0x21, 0x41, 0x45, 0x4B, 0x31,// 3 39 | 0x18, 0x14, 0x12, 0x7F, 0x10,// 4 40 | 0x27, 0x45, 0x45, 0x45, 0x39,// 5 41 | 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6 42 | 0x01, 0x71, 0x09, 0x05, 0x03,// 7 43 | 0x36, 0x49, 0x49, 0x49, 0x36,// 8 44 | 0x06, 0x49, 0x49, 0x29, 0x1E,// 9 45 | 0x00, 0x36, 0x36, 0x00, 0x00,// : 46 | 0x00, 0x56, 0x36, 0x00, 0x00,// ; 47 | 0x00, 0x08, 0x14, 0x22, 0x41,// < 48 | 0x14, 0x14, 0x14, 0x14, 0x14,// = 49 | 0x41, 0x22, 0x14, 0x08, 0x00,// > 50 | 0x02, 0x01, 0x51, 0x09, 0x06,// ? 51 | 0x32, 0x49, 0x79, 0x41, 0x3E,// @ 52 | 0x7E, 0x11, 0x11, 0x11, 0x7E,// A 53 | 0x7F, 0x49, 0x49, 0x49, 0x36,// B 54 | 0x3E, 0x41, 0x41, 0x41, 0x22,// C 55 | 0x7F, 0x41, 0x41, 0x22, 0x1C,// D 56 | 0x7F, 0x49, 0x49, 0x49, 0x41,// E 57 | 0x7F, 0x09, 0x09, 0x01, 0x01,// F 58 | 0x3E, 0x41, 0x41, 0x51, 0x32,// G 59 | 0x7F, 0x08, 0x08, 0x08, 0x7F,// H 60 | 0x00, 0x41, 0x7F, 0x41, 0x00,// I 61 | 0x20, 0x40, 0x41, 0x3F, 0x01,// J 62 | 0x7F, 0x08, 0x14, 0x22, 0x41,// K 63 | 0x7F, 0x40, 0x40, 0x40, 0x40,// L 64 | 0x7F, 0x02, 0x04, 0x02, 0x7F,// M 65 | 0x7F, 0x04, 0x08, 0x10, 0x7F,// N 66 | 0x3E, 0x41, 0x41, 0x41, 0x3E,// O 67 | 0x7F, 0x09, 0x09, 0x09, 0x06,// P 68 | 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q 69 | 0x7F, 0x09, 0x19, 0x29, 0x46,// R 70 | 0x46, 0x49, 0x49, 0x49, 0x31,// S 71 | 0x01, 0x01, 0x7F, 0x01, 0x01,// T 72 | 0x3F, 0x40, 0x40, 0x40, 0x3F,// U 73 | 0x1F, 0x20, 0x40, 0x20, 0x1F,// V 74 | 0x7F, 0x20, 0x18, 0x20, 0x7F,// W 75 | 0x63, 0x14, 0x08, 0x14, 0x63,// X 76 | 0x03, 0x04, 0x78, 0x04, 0x03,// Y 77 | 0x61, 0x51, 0x49, 0x45, 0x43,// Z 78 | 0x00, 0x00, 0x7F, 0x41, 0x41,// [ 79 | 0x02, 0x04, 0x08, 0x10, 0x20,// "\" 80 | 0x41, 0x41, 0x7F, 0x00, 0x00,// ] 81 | 0x04, 0x02, 0x01, 0x02, 0x04,// ^ 82 | 0x40, 0x40, 0x40, 0x40, 0x40,// _ 83 | 0x00, 0x01, 0x02, 0x04, 0x00,// ` 84 | 0x20, 0x54, 0x54, 0x54, 0x78,// a 85 | 0x7F, 0x48, 0x44, 0x44, 0x38,// b 86 | 0x38, 0x44, 0x44, 0x44, 0x20,// c 87 | 0x38, 0x44, 0x44, 0x48, 0x7F,// d 88 | 0x38, 0x54, 0x54, 0x54, 0x18,// e 89 | 0x08, 0x7E, 0x09, 0x01, 0x02,// f 90 | 0x08, 0x14, 0x54, 0x54, 0x3C,// g 91 | 0x7F, 0x08, 0x04, 0x04, 0x78,// h 92 | 0x00, 0x44, 0x7D, 0x40, 0x00,// i 93 | 0x20, 0x40, 0x44, 0x3D, 0x00,// j 94 | 0x00, 0x7F, 0x10, 0x28, 0x44,// k 95 | 0x00, 0x41, 0x7F, 0x40, 0x00,// l 96 | 0x7C, 0x04, 0x18, 0x04, 0x78,// m 97 | 0x7C, 0x08, 0x04, 0x04, 0x78,// n 98 | 0x38, 0x44, 0x44, 0x44, 0x38,// o 99 | 0x7C, 0x14, 0x14, 0x14, 0x08,// p 100 | 0x08, 0x14, 0x14, 0x18, 0x7C,// q 101 | 0x7C, 0x08, 0x04, 0x04, 0x08,// r 102 | 0x48, 0x54, 0x54, 0x54, 0x20,// s 103 | 0x04, 0x3F, 0x44, 0x40, 0x20,// t 104 | 0x3C, 0x40, 0x40, 0x20, 0x7C,// u 105 | 0x1C, 0x20, 0x40, 0x20, 0x1C,// v 106 | 0x3C, 0x40, 0x30, 0x40, 0x3C,// w 107 | 0x44, 0x28, 0x10, 0x28, 0x44,// x 108 | 0x0C, 0x50, 0x50, 0x50, 0x3C,// y 109 | 0x44, 0x64, 0x54, 0x4C, 0x44,// z 110 | 0x00, 0x08, 0x36, 0x41, 0x00,// { 111 | 0x00, 0x00, 0x7F, 0x00, 0x00,// | 112 | 0x00, 0x41, 0x36, 0x08, 0x00,// } 113 | 0x08, 0x08, 0x2A, 0x1C, 0x08,// -> 114 | 0x08, 0x1C, 0x2A, 0x08, 0x08, // <- 115 | 0x00, 0x06, 0x09, 0x09, 0x06 // degree symbol 116 | 117 | }; 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /peripheral_lib/inc/stm32f0xx_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file contains all the functions prototypes for the DBGMCU firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F0XX_DBGMCU_H 31 | #define __STM32F0XX_DBGMCU_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f0xx.h" 39 | 40 | /** @addtogroup STM32F0xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup DBGMCU 45 | * @{ 46 | */ 47 | /* Exported types ------------------------------------------------------------*/ 48 | /* Exported constants --------------------------------------------------------*/ 49 | 50 | 51 | /** @defgroup DBGMCU_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | #define DBGMCU_STOP DBGMCU_CR_DBG_STOP 56 | #define DBGMCU_STANDBY DBGMCU_CR_DBG_STANDBY 57 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFFFFFF9) == 0x00) && ((PERIPH) != 0x00)) 58 | 59 | #define DBGMCU_TIM2_STOP DBGMCU_APB1_FZ_DBG_TIM2_STOP /*!< Not applicable for STM32F030 devices */ 60 | #define DBGMCU_TIM3_STOP DBGMCU_APB1_FZ_DBG_TIM3_STOP 61 | #define DBGMCU_TIM6_STOP DBGMCU_APB1_FZ_DBG_TIM6_STOP 62 | #define DBGMCU_TIM7_STOP DBGMCU_APB1_FZ_DBG_TIM7_STOP /*!< Only applicable for STM32F072 devices */ 63 | #define DBGMCU_TIM14_STOP DBGMCU_APB1_FZ_DBG_TIM14_STOP 64 | #define DBGMCU_RTC_STOP DBGMCU_APB1_FZ_DBG_RTC_STOP 65 | #define DBGMCU_WWDG_STOP DBGMCU_APB1_FZ_DBG_WWDG_STOP 66 | #define DBGMCU_IWDG_STOP DBGMCU_APB1_FZ_DBG_IWDG_STOP 67 | #define DBGMCU_I2C1_SMBUS_TIMEOUT DBGMCU_APB1_FZ_DBG_I2C1_SMBUS_TIMEOUT 68 | #define DBGMCU_CAN1_STOP DBGMCU_APB1_FZ_DBG_CAN1_STOP /*!< Only applicable for STM32F042 and STM32F072 devices */ 69 | #define IS_DBGMCU_APB1PERIPH(PERIPH) ((((PERIPH) & 0xFDDFE2CC) == 0x00) && ((PERIPH) != 0x00)) 70 | 71 | #define DBGMCU_TIM1_STOP DBGMCU_APB2_FZ_DBG_TIM1_STOP 72 | #define DBGMCU_TIM15_STOP DBGMCU_APB2_FZ_DBG_TIM15_STOP 73 | #define DBGMCU_TIM16_STOP DBGMCU_APB2_FZ_DBG_TIM16_STOP 74 | #define DBGMCU_TIM17_STOP DBGMCU_APB2_FZ_DBG_TIM17_STOP 75 | #define IS_DBGMCU_APB2PERIPH(PERIPH) ((((PERIPH) & 0xFFF8F7FF) == 0x00) && ((PERIPH) != 0x00)) 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Exported macro ------------------------------------------------------------*/ 82 | /* Exported functions ------------------------------------------------------- */ 83 | 84 | /* Device and Revision ID management functions ********************************/ 85 | uint32_t DBGMCU_GetREVID(void); 86 | uint32_t DBGMCU_GetDEVID(void); 87 | 88 | /* Peripherals Configuration functions ****************************************/ 89 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 90 | void DBGMCU_APB1PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 91 | void DBGMCU_APB2PeriphConfig(uint32_t DBGMCU_Periph, FunctionalState NewState); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* __STM32F0XX_DBGMCU_H */ 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 108 | -------------------------------------------------------------------------------- /pcb/openground_cc2500.sch: -------------------------------------------------------------------------------- 1 | EESchema Schematic File Version 2 2 | LIBS:power 3 | LIBS:device 4 | LIBS:transistors 5 | LIBS:conn 6 | LIBS:linear 7 | LIBS:regul 8 | LIBS:74xx 9 | LIBS:cmos4000 10 | LIBS:adc-dac 11 | LIBS:memory 12 | LIBS:xilinx 13 | LIBS:special 14 | LIBS:microcontrollers 15 | LIBS:dsp 16 | LIBS:microchip 17 | LIBS:analog_switches 18 | LIBS:motorola 19 | LIBS:texas 20 | LIBS:intel 21 | LIBS:audio 22 | LIBS:interface 23 | LIBS:digital-audio 24 | LIBS:philips 25 | LIBS:display 26 | LIBS:cypress 27 | LIBS:siliconi 28 | LIBS:opto 29 | LIBS:atmel 30 | LIBS:contrib 31 | LIBS:valves 32 | LIBS:custom 33 | EELAYER 27 0 34 | EELAYER END 35 | $Descr A4 11693 8268 36 | encoding utf-8 37 | Sheet 1 1 38 | Title "" 39 | Date "5 oct 2016" 40 | Rev "" 41 | Comp "" 42 | Comment1 "" 43 | Comment2 "" 44 | Comment3 "" 45 | Comment4 "" 46 | $EndDescr 47 | $Comp 48 | L FS-I6S_FOOTPRINT U1 49 | U 1 1 57F4E071 50 | P 3100 3050 51 | F 0 "U1" H 3000 2350 60 0000 C CNN 52 | F 1 "FS-I6S_FOOTPRINT" H 3050 4150 60 0000 C CNN 53 | F 2 "" H 3000 2350 60 0000 C CNN 54 | F 3 "" H 3000 2350 60 0000 C CNN 55 | 1 3100 3050 56 | 1 0 0 -1 57 | $EndComp 58 | $Comp 59 | L CC2500_FOOTPRINT U2 60 | U 1 1 57F4E080 61 | P 6300 3050 62 | F 0 "U2" H 6250 5050 60 0000 C CNN 63 | F 1 "CC2500_FOOTPRINT" H 6250 5150 60 0000 C CNN 64 | F 2 "" H 6300 3050 60 0000 C CNN 65 | F 3 "" H 6300 3050 60 0000 C CNN 66 | 1 6300 3050 67 | 1 0 0 -1 68 | $EndComp 69 | $Comp 70 | L GND #PWR01 71 | U 1 1 57F4E0F8 72 | P 3050 4000 73 | F 0 "#PWR01" H 3050 4000 30 0001 C CNN 74 | F 1 "GND" H 3050 3930 30 0001 C CNN 75 | F 2 "" H 3050 4000 60 0000 C CNN 76 | F 3 "" H 3050 4000 60 0000 C CNN 77 | 1 3050 4000 78 | 1 0 0 -1 79 | $EndComp 80 | $Comp 81 | L GND #PWR02 82 | U 1 1 57F4E134 83 | P 6300 4650 84 | F 0 "#PWR02" H 6300 4650 30 0001 C CNN 85 | F 1 "GND" H 6300 4580 30 0001 C CNN 86 | F 2 "" H 6300 4650 60 0000 C CNN 87 | F 3 "" H 6300 4650 60 0000 C CNN 88 | 1 6300 4650 89 | 1 0 0 -1 90 | $EndComp 91 | $Comp 92 | L GND #PWR03 93 | U 1 1 57F4E31A 94 | P 6350 1300 95 | F 0 "#PWR03" H 6350 1300 30 0001 C CNN 96 | F 1 "GND" H 6350 1230 30 0001 C CNN 97 | F 2 "" H 6350 1300 60 0000 C CNN 98 | F 3 "" H 6350 1300 60 0000 C CNN 99 | 1 6350 1300 100 | 1 0 0 -1 101 | $EndComp 102 | NoConn ~ 2200 3100 103 | NoConn ~ 3950 2650 104 | NoConn ~ 2200 2650 105 | Wire Wire Line 106 | 2000 4250 5900 4250 107 | Wire Wire Line 108 | 2000 4250 2000 3600 109 | Wire Wire Line 110 | 2000 3600 2200 3600 111 | Wire Wire Line 112 | 5900 4250 5900 4000 113 | Wire Wire Line 114 | 5800 4000 5800 4150 115 | Wire Wire Line 116 | 5800 4150 4050 4150 117 | Wire Wire Line 118 | 4050 4150 4050 3600 119 | Wire Wire Line 120 | 4050 3600 3950 3600 121 | Wire Wire Line 122 | 6000 4000 6000 4350 123 | Wire Wire Line 124 | 6000 4350 1900 4350 125 | Wire Wire Line 126 | 1900 4350 1900 3500 127 | Wire Wire Line 128 | 1900 3500 2200 3500 129 | Wire Wire Line 130 | 6100 4000 6100 4450 131 | Wire Wire Line 132 | 6100 4450 4250 4450 133 | Wire Wire Line 134 | 4250 4450 4250 3400 135 | Wire Wire Line 136 | 4150 3500 3950 3500 137 | Wire Wire Line 138 | 2100 3900 4150 3900 139 | Wire Wire Line 140 | 2100 3300 2200 3300 141 | Wire Wire Line 142 | 3050 4000 3050 3900 143 | Connection ~ 3050 3900 144 | Wire Wire Line 145 | 6300 4000 6300 4650 146 | Wire Wire Line 147 | 6200 4000 6200 4550 148 | Wire Wire Line 149 | 6200 4550 4350 4550 150 | Wire Wire Line 151 | 4350 4550 4350 3300 152 | Wire Wire Line 153 | 6400 4000 6400 4800 154 | Wire Wire Line 155 | 6400 4800 1800 4800 156 | Wire Wire Line 157 | 1800 4800 1800 3200 158 | Wire Wire Line 159 | 1800 3200 2200 3200 160 | Wire Wire Line 161 | 6500 4000 6500 4900 162 | Wire Wire Line 163 | 6500 4900 1700 4900 164 | Wire Wire Line 165 | 1700 4900 1700 3400 166 | Wire Wire Line 167 | 1700 3400 2200 3400 168 | Wire Wire Line 169 | 6600 4000 6600 5000 170 | Wire Wire Line 171 | 6600 5000 4450 5000 172 | Wire Wire Line 173 | 4450 5000 4450 3100 174 | Wire Wire Line 175 | 6700 4000 6700 5100 176 | Wire Wire Line 177 | 6700 5100 4550 5100 178 | Wire Wire Line 179 | 4550 5100 4550 3200 180 | Connection ~ 2100 3300 181 | Connection ~ 4150 3500 182 | Wire Wire Line 183 | 6850 1200 6850 1400 184 | Wire Wire Line 185 | 6350 1200 6350 1300 186 | Connection ~ 6350 1200 187 | Wire Wire Line 188 | 6350 1200 6850 1200 189 | Wire Wire Line 190 | 4350 3300 3950 3300 191 | Wire Wire Line 192 | 4250 3400 3950 3400 193 | Wire Wire Line 194 | 2100 3900 2100 3300 195 | Wire Wire Line 196 | 4150 3900 4150 3500 197 | NoConn ~ 3950 2750 198 | NoConn ~ 3950 2550 199 | NoConn ~ 2200 2550 200 | NoConn ~ 2200 2750 201 | Wire Wire Line 202 | 4450 3100 3950 3100 203 | Wire Wire Line 204 | 4550 3200 3950 3200 205 | $EndSCHEMATC 206 | -------------------------------------------------------------------------------- /src/frsky.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef FRSKY_H_ 21 | #define FRSKY_H_ 22 | 23 | #include 24 | 25 | #include "main.h" 26 | #include "cc2500.h" 27 | 28 | #define FRSKY_HOPTABLE_SIZE 47 29 | #define FRSKY_PACKET_LENGTH 17 30 | #define FRSKY_PACKET_BUFFER_SIZE (FRSKY_PACKET_LENGTH+3) 31 | #define FRSKY_COUNT_RXSTATS 20 32 | 33 | void frsky_init(void); 34 | uint8_t frsky_check_transceiver(void); 35 | void frsky_configure(void); 36 | uint8_t frsky_bind_jumper_set(void); 37 | void frsky_enter_bindmode(void); 38 | void frsky_configure_address(void); 39 | void frsky_autotune(void); 40 | void frsky_enter_rxmode(uint8_t channel); 41 | void frsky_tune_channel(uint8_t ch); 42 | void frsky_handle_overflows(void); 43 | void frsky_fetch_txid_and_hoptable(void); 44 | void frsky_calib_pll(void); 45 | // void frsky_main(void); 46 | void frsky_handle_telemetry(void); 47 | 48 | uint8_t frsky_extract_rssi(uint8_t rssi_raw); 49 | void frsky_increment_channel(int8_t cnt); 50 | void frsky_tx_set_enabled(uint32_t enabled); 51 | void frsky_set_channel(uint8_t hop_index); 52 | void frsky_send_telemetry(uint8_t telemetry_id); 53 | void frsky_send_bindpacket(uint8_t bind_packet_id); 54 | 55 | 56 | void frsky_do_clone_prepare(void); 57 | void frsky_do_clone_finish(void); 58 | void frsky_autotune_prepare(void); 59 | uint32_t frsky_autotune_do(void); 60 | void frsky_autotune_finish(void); 61 | void frsky_fetch_txid_and_hoptable_prepare(void); 62 | uint32_t frsky_fetch_txid_and_hoptable_do(void); 63 | void frsky_fetch_txid_and_hoptable_finish(void); 64 | 65 | void frsky_init_timer(void); 66 | 67 | void frsky_get_rssi(uint8_t *rssi, uint8_t *rssi_telemetry); 68 | 69 | // extern uint8_t frsky_current_ch_idx; 70 | // extern uint8_t frsky_diversity_count; 71 | // rssi 72 | // extern uint8_t frsky_rssi; 73 | // extern uint8_t frsky_link_quality; 74 | // pll calibration 75 | // extern uint8_t frsky_calib_fscal1_table[FRSKY_HOPTABLE_SIZE]; 76 | // extern uint8_t frsky_calib_fscal2; 77 | // extern uint8_t frsky_calib_fscal3; 78 | // 79 | // extern volatile uint8_t frsky_packet_buffer[FRSKY_PACKET_BUFFER_SIZE]; 80 | // extern volatile uint8_t frsky_packet_received; 81 | // extern volatile uint8_t frsky_packet_sent; 82 | 83 | 84 | 85 | /* 86 | void frsky_fetch_txid_and_hoptable(void); 87 | void frsky_configure_address(void); 88 | void frsky_calib_pll(void); 89 | void frsky_rf_interrupt(void) __interrupt RF_VECTOR; 90 | void frsky_handle_overflows(void); 91 | void frsky_setup_rf_dma(uint8_t); 92 | uint8_t frsky_extract_rssi(uint8_t rssi_raw); 93 | void frsky_enter_rxmode(uint8_t ch); 94 | void frsky_frame_sniffer(void); 95 | uint8_t frsky_append_hub_data(uint8_t sensor_id, uint16_t value, uint8_t *buf); 96 | 97 | // binding 98 | uint8_t frsky_bind_jumper_set(void); 99 | void frsky_do_bind(void); 100 | void frsky_store_config(void); 101 | */ 102 | 103 | 104 | // packet data example: 105 | // BIND: [11 03 01 16 68 14 7E BF 15 56 97 00 00 00 00 00 00 0B F8 AF ] 106 | // NORMAL: [11 16 68 ... ] 107 | // TX: 11 16 68 7A 1B 0B CA CB CF C4 88 85 CB CB CB 92 8B 78 21 AF 108 | // TELEMETRY WITH HUB: 11 16 68 60 64 5B 00 00 5E 3B 09 00 5E 5E 3B 09 00 5E 48 B1 109 | #define FRSKY_VALID_FRAMELENGTH(_b) (_b[0] == 0x11) 110 | #define FRSKY_VALID_CRC(_b) (_b[19] & 0x80) 111 | #define FRSKY_VALID_TXID(_b) ((_b[1] == storage.frsky_txid[0]) && (_b[2] == storage.frsky_txid[1])) 112 | #define FRSKY_VALID_PACKET_BIND(_b) \ 113 | (FRSKY_VALID_FRAMELENGTH(_b) && FRSKY_VALID_CRC(_b) && (_b[2] == 0x01)) 114 | #define FRSKY_VALID_PACKET(_b) \ 115 | (FRSKY_VALID_FRAMELENGTH(_b) && FRSKY_VALID_CRC(_b) && FRSKY_VALID_TXID(_b) ) 116 | 117 | /* 118 | #define FRSKY_HUB_TELEMETRY_HEADER 0x5E 119 | #define FRSKY_HUB_TELEMETRY_VOLTAGE 0x39 //not really documented, seems to be volt in 0.1V steps... 120 | #define FRSKY_HUB_TELEMETRY_VOLTAGE_BEFORE 0x3A 121 | #define FRSKY_HUB_TELEMETRY_VOLTAGE_AFTER 0x3B 122 | #define FRSKY_HUB_TELEMETRY_CURRENT 0x28 123 | */ 124 | 125 | #endif // FRSKY_H_ 126 | -------------------------------------------------------------------------------- /peripheral_lib/inc/stm32f0xx_misc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_misc.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file contains all the functions prototypes for the miscellaneous 8 | * firmware library functions (add-on to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F0XX_MISC_H 31 | #define __STM32F0XX_MISC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f0xx.h" 39 | 40 | /** @addtogroup STM32F0xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup MISC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief NVIC Init Structure definition 52 | */ 53 | 54 | typedef struct 55 | { 56 | uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. 57 | This parameter can be a value of @ref IRQn_Type 58 | (For the complete STM32 Devices IRQ Channels list, 59 | please refer to stm32f0xx.h file) */ 60 | 61 | uint8_t NVIC_IRQChannelPriority; /*!< Specifies the priority level for the IRQ channel specified 62 | in NVIC_IRQChannel. This parameter can be a value 63 | between 0 and 3. */ 64 | 65 | FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel 66 | will be enabled or disabled. 67 | This parameter can be set either to ENABLE or DISABLE */ 68 | } NVIC_InitTypeDef; 69 | 70 | /** 71 | * 72 | @verbatim 73 | 74 | @endverbatim 75 | */ 76 | 77 | /* Exported constants --------------------------------------------------------*/ 78 | 79 | /** @defgroup MISC_Exported_Constants 80 | * @{ 81 | */ 82 | 83 | /** @defgroup MISC_System_Low_Power 84 | * @{ 85 | */ 86 | 87 | #define NVIC_LP_SEVONPEND ((uint8_t)0x10) 88 | #define NVIC_LP_SLEEPDEEP ((uint8_t)0x04) 89 | #define NVIC_LP_SLEEPONEXIT ((uint8_t)0x02) 90 | #define IS_NVIC_LP(LP) (((LP) == NVIC_LP_SEVONPEND) || \ 91 | ((LP) == NVIC_LP_SLEEPDEEP) || \ 92 | ((LP) == NVIC_LP_SLEEPONEXIT)) 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup MISC_Preemption_Priority_Group 98 | * @{ 99 | */ 100 | #define IS_NVIC_PRIORITY(PRIORITY) ((PRIORITY) < 0x04) 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /** @defgroup MISC_SysTick_clock_source 107 | * @{ 108 | */ 109 | 110 | #define SysTick_CLKSource_HCLK_Div8 ((uint32_t)0xFFFFFFFB) 111 | #define SysTick_CLKSource_HCLK ((uint32_t)0x00000004) 112 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SysTick_CLKSource_HCLK) || \ 113 | ((SOURCE) == SysTick_CLKSource_HCLK_Div8)) 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /* Exported macro ------------------------------------------------------------*/ 123 | /* Exported functions ------------------------------------------------------- */ 124 | 125 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); 126 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState); 127 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __STM32F0XX_MISC_H */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 144 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #ifndef CONFIG_H_ 21 | #define CONFIG_H_ 22 | #include "main.h" 23 | 24 | 25 | typedef enum { 26 | CONFIG_HW_REVISION_I6S = 0, 27 | CONFIG_HW_REVISION_EVOLUTION, 28 | CONFIG_HW_REVISION_SIZE 29 | } config_hw_revision_t; 30 | 31 | extern config_hw_revision_t config_hw_revision; 32 | void config_init(void); 33 | void config_detect_hw_revision(void); 34 | 35 | // see http://fishpepper.de/2016/09/15/openground-part-1-components-pinout/ 36 | // for pin mappings on flysky fs-i6s 37 | 38 | 39 | // revision selection button 40 | #define HW_REVISION_GPIO GPIOE 41 | #define HW_REVISION_PIN GPIO10 42 | 43 | // LEDS 44 | #define LED_BACKLIGHT_GPIO GPIOF 45 | #define LED_BACKLIGHT_PIN GPIO3 46 | 47 | // L BUTTON BLUE = PD10 48 | // R BUTTON BLUE = PD11 49 | #define LED_BUTTON_L_GPIO GPIOD 50 | #define LED_BUTTON_L_PIN GPIO10 51 | #define LED_BUTTON_R_GPIO GPIOD 52 | #define LED_BUTTON_R_PIN GPIO11 53 | 54 | // POWERDOWN TRIGGER 55 | #define POWERDOWN_GPIO GPIOB 56 | #define POWERDOWN_PIN GPIO15 57 | 58 | 59 | // LCD 60 | // data lines 61 | #define LCD_DATA_GPIO GPIOE 62 | // RW 63 | #define LCD_RW_GPIO GPIOB 64 | #define LCD_RW_PIN GPIO5 65 | // RST 66 | #define LCD_RST_GPIO GPIOB 67 | #define LCD_RST_PIN GPIO4 68 | // RS 69 | #define LCD_RS_GPIO GPIOB 70 | #define LCD_RS_PIN GPIO3 71 | // RD 72 | #define LCD_RD_GPIO GPIOD 73 | #define LCD_RD_PIN GPIO7 74 | // CS 75 | #define LCD_CS_GPIO GPIOD 76 | #define LCD_CS_PIN GPIO2 77 | 78 | // speaker 79 | #define SPEAKER_GPIO GPIOA 80 | #define SPEAKER_PIN GPIO8 81 | 82 | // irq priorities 83 | #define NVIC_PRIO_FRSKY 0*64 84 | #define NVIC_PRIO_SYSTICK 1*64 85 | #define NVIC_PRIO_TOUCH 3*64 86 | 87 | // touch 88 | #define TOUCH_FT6236_I2C_ADDRESS (0x70>>1) 89 | #define TOUCH_I2C I2C1 90 | #define TOUCH_I2C_CLK RCC_I2C1 91 | #define TOUCH_I2C_GPIO GPIOB 92 | #define TOUCH_I2C_SDA_PIN GPIO9 93 | #define TOUCH_I2C_SCL_PIN GPIO8 94 | 95 | #define TOUCH_RESET_GPIO GPIOA 96 | #define TOUCH_RESET_PIN GPIO15 97 | 98 | #define TOUCH_INT_GPIO GPIOC 99 | #define TOUCH_INT_PIN GPIO12 100 | 101 | #define TOUCH_INT_EXTI_SOURCE GPIOC 102 | #define TOUCH_INT_EXTI_SOURCE_LINE EXTI12 103 | #define TOUCH_INT_EXTI_IRQN NVIC_EXTI4_15_IRQ 104 | 105 | 106 | 107 | #define ADC_DMA_CHANNEL DMA_CHANNEL1 108 | #define ADC_DMA_TC_FLAG DMA_ISR_TCIF1 109 | #define ADC_CHANNEL_COUNT 11 110 | 111 | // cc2500 module connection 112 | // SI = SDIO 113 | // SCK = SCK 114 | // MISO = GD1 115 | // GDO2 = GDO2 116 | // GDO0 = RF1 117 | // CSN = SCS 118 | // PA_EN = TX = TXW 119 | // LNA_EN = RX = RXW 120 | #define CC2500_SPI_GPIO GPIOE 121 | // LABELED SCK 122 | #define CC2500_SPI_SCK_PIN GPIO13 123 | // LABELED SPIO 124 | #define CC2500_SPI_MOSI_PIN GPIO15 125 | // LABELED GIO1 126 | #define CC2500_SPI_MISO_PIN GPIO14 127 | // LABELED RF2 128 | #define CC2500_SPI_CSN_PIN GPIO12 129 | #define CC2500_SPI SPI1 130 | #define CC2500_SPI SPI1 131 | #define CC2500_SPI_DR SPI1_DR 132 | #define CC2500_SPI_CLK RCC_SPI1 133 | #define CC2500_SPI_DMA_CLOCK RCC_DMA1 134 | #define CC2500_SPI_TX_DMA_CHANNEL DMA_CHANNEL3 135 | #define CC2500_SPI_RX_DMA_CHANNEL DMA_CHANNEL2 136 | 137 | // LABELED RF1 138 | #define CC2500_GDO1_PIN GPIO11 139 | #define CC2500_GDO1_GPIO GPIOE 140 | 141 | // LABELED RX-W 142 | #define CC2500_LNA_GPIO GPIOE 143 | #define CC2500_LNA_PIN GPIO9 144 | 145 | // LABELED TX_W 146 | #define CC2500_PA_GPIO GPIOE 147 | #define CC2500_PA_PIN GPIO8 148 | 149 | // LABELED GIO2 150 | #define CC2500_GDO2_GPIO GPIOB 151 | #define CC2500_GDO2_PIN GPIO2 152 | 153 | // BUTTONS 154 | #define BUTTON_POWER_BOTH_GPIO GPIOB 155 | #define BUTTON_POWER_BOTH_PIN GPIO14 156 | 157 | // BUTTON_BACK_RIGHT = PA10 158 | // BUTTON_BACK_LEFT = PA9 159 | 160 | #define USB_GPIO GPIOA 161 | #define USB_DP_PIN GPIO12 162 | #define USB_DM_PIN GPIO11 163 | 164 | #endif // CONFIG_H_ 165 | -------------------------------------------------------------------------------- /peripheral_lib/inc/stm32f0xx_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_iwdg.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F0XX_IWDG_H 31 | #define __STM32F0XX_IWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f0xx.h" 39 | 40 | /** @addtogroup STM32F0xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup IWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup IWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup IWDG_WriteAccess 56 | * @{ 57 | */ 58 | 59 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 60 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 61 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 62 | ((ACCESS) == IWDG_WriteAccess_Disable)) 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @defgroup IWDG_prescaler 68 | * @{ 69 | */ 70 | 71 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 72 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 73 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 74 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 75 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 76 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 77 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 78 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 79 | ((PRESCALER) == IWDG_Prescaler_8) || \ 80 | ((PRESCALER) == IWDG_Prescaler_16) || \ 81 | ((PRESCALER) == IWDG_Prescaler_32) || \ 82 | ((PRESCALER) == IWDG_Prescaler_64) || \ 83 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 84 | ((PRESCALER) == IWDG_Prescaler_256)) 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup IWDG_Flag 90 | * @{ 91 | */ 92 | 93 | #define IWDG_FLAG_PVU IWDG_SR_PVU 94 | #define IWDG_FLAG_RVU IWDG_SR_RVU 95 | #define IWDG_FLAG_WVU IWDG_SR_WVU 96 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU) || \ 97 | ((FLAG) == IWDG_FLAG_WVU)) 98 | 99 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 100 | 101 | #define IS_IWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0xFFF) 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /* Exported macro ------------------------------------------------------------*/ 111 | /* Exported functions ------------------------------------------------------- */ 112 | 113 | /* Prescaler and Counter configuration functions ******************************/ 114 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 115 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 116 | void IWDG_SetReload(uint16_t Reload); 117 | void IWDG_ReloadCounter(void); 118 | void IWDG_SetWindowValue(uint16_t WindowValue); 119 | 120 | /* IWDG activation function ***************************************************/ 121 | void IWDG_Enable(void); 122 | 123 | /* Flag management function ***************************************************/ 124 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* __STM32F0XX_IWDG_H */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /pcb/custom.lib: -------------------------------------------------------------------------------- 1 | EESchema-LIBRARY Version 2.3 Date: Wed 05 Oct 2016 01:49:45 PM CEST 2 | #encoding utf-8 3 | # 4 | # CC2500_FOOTPRINT 5 | # 6 | DEF CC2500_FOOTPRINT U 0 40 Y Y 1 F N 7 | F0 "U" -50 2000 60 H V C CNN 8 | F1 "CC2500_FOOTPRINT" -50 2100 60 H V C CNN 9 | F2 "~" 0 0 60 H V C CNN 10 | F3 "~" 0 0 60 H V C CNN 11 | DRAW 12 | S -550 -650 650 1350 0 1 0 N 13 | X vcc 1 -500 -950 300 U 50 50 1 1 I 14 | X SI 2 -400 -950 300 U 50 50 1 1 I 15 | X SCLK 3 -300 -950 300 U 50 50 1 1 I 16 | X SO 4 -200 -950 300 U 50 50 1 1 I 17 | X GDO2 5 -100 -950 300 U 50 50 1 1 I 18 | X GND 6 0 -950 300 U 50 50 1 1 I 19 | X GDO0 7 100 -950 300 U 50 50 1 1 I 20 | X CSn 8 200 -950 300 U 50 50 1 1 I 21 | X PA_EN 9 300 -950 300 U 50 50 1 1 I 22 | X LNA_EN 10 400 -950 300 U 50 50 1 1 I 23 | X MOUNT_A 11 550 1650 300 D 50 50 1 1 I 24 | ENDDRAW 25 | ENDDEF 26 | # 27 | # CC2510 28 | # 29 | DEF CC2510 U 0 40 Y Y 1 F N 30 | F0 "U" -200 150 60 H V C CNN 31 | F1 "CC2510" -200 250 60 H V C CNN 32 | F2 "~" 0 0 60 H V C CNN 33 | F3 "~" 0 0 60 H V C CNN 34 | DRAW 35 | S -750 700 850 -600 0 1 0 N 36 | X P1_2 1 -1050 400 300 R 50 50 1 1 B 37 | X DVDD 2 -1050 300 300 R 50 50 1 1 W 38 | X P1_1 3 -1050 200 300 R 50 50 1 1 B 39 | X P1_0 4 -1050 100 300 R 50 50 1 1 B 40 | X P0_0 5 -1050 0 300 R 50 50 1 1 B 41 | X P0_1 6 -1050 -100 300 R 50 50 1 1 B 42 | X P0_2 7 -1050 -200 300 R 50 50 1 1 B 43 | X P0_3 8 -1050 -300 300 R 50 50 1 1 B 44 | X P0_4 9 -1050 -400 300 R 50 50 1 1 B 45 | X DVDD 10 -400 -900 300 U 50 50 1 1 W 46 | X XOSC_2 20 1150 -300 300 L 50 50 1 1 B 47 | X DCOUPL 30 200 1000 300 D 50 50 1 1 w 48 | X P0_5 11 -300 -900 300 U 50 50 1 1 B 49 | X XOSC_1 21 1150 -200 300 L 50 50 1 1 B 50 | X ~RESET 31 100 1000 300 D 50 50 1 1 B 51 | X P0_6 12 -200 -900 300 U 50 50 1 1 B 52 | X AVDD 22 1150 -100 300 L 50 50 1 1 W 53 | X P1_7 32 0 1000 300 D 50 50 1 1 B 54 | X P0_7 13 -100 -900 300 U 50 50 1 1 B 55 | X RF_P 23 1150 0 300 L 50 50 1 1 B 56 | X P1_6 33 -100 1000 300 D 50 50 1 1 B 57 | X P2_0 14 0 -900 300 U 50 50 1 1 B 58 | X RF_B 24 1150 100 300 L 50 50 1 1 B 59 | X P1_5 34 -200 1000 300 D 50 50 1 1 B 60 | X P2_1__DBG_DATA 15 100 -900 300 U 50 50 1 1 B 61 | X AVDD 25 1150 200 300 L 50 50 1 1 W 62 | X P1_4 35 -300 1000 300 D 50 50 1 1 B 63 | X P2_2__DBG_CLOCK 16 200 -900 300 U 50 50 1 1 B 64 | X AVDD 26 1150 300 300 L 50 50 1 1 W 65 | X P1_3 36 -400 1000 300 D 50 50 1 1 B 66 | X P2_3__XOSC32_1 17 300 -900 300 U 50 50 1 1 B 67 | X RBIAS 27 1150 400 300 L 50 50 1 1 B 68 | X P2_4__XOSC32_2 18 400 -900 300 U 50 50 1 1 B 69 | X GUARD 28 400 1000 300 D 50 50 1 1 B 70 | X AVDD 19 1150 -400 300 L 50 50 1 1 W 71 | X AVDD_DREG 29 300 1000 300 D 50 50 1 1 w 72 | X GND GND 500 -900 300 U 50 50 1 1 W 73 | ENDDRAW 74 | ENDDEF 75 | # 76 | # CRYSTAL 77 | # 78 | DEF CRYSTAL X 0 40 N N 1 F N 79 | F0 "X" 0 150 60 H V C CNN 80 | F1 "CRYSTAL" 0 -150 60 H V C CNN 81 | F2 "~" 0 0 60 H V C CNN 82 | F3 "~" 0 0 60 H V C CNN 83 | DRAW 84 | P 2 0 1 16 -100 100 -100 -100 N 85 | P 2 0 1 16 100 100 100 -100 N 86 | P 5 0 1 12 -50 50 50 50 50 -50 -50 -50 -50 50 f 87 | X 1 1 -300 0 200 R 40 40 1 1 P 88 | X 3 3 300 0 200 L 40 40 1 1 P 89 | ENDDRAW 90 | ENDDEF 91 | # 92 | # FS-I6S_FOOTPRINT 93 | # 94 | DEF FS-I6S_FOOTPRINT U 0 40 Y Y 1 F N 95 | F0 "U" -100 -700 60 H V C CNN 96 | F1 "FS-I6S_FOOTPRINT" -50 1100 60 H V C CNN 97 | F2 "~" -100 -700 60 H V C CNN 98 | F3 "~" -100 -700 60 H V C CNN 99 | DRAW 100 | S -600 1250 550 -650 0 1 0 N 101 | X SDIO 1 -900 -550 300 R 50 50 1 1 I 102 | X SCK 2 -900 -450 300 R 50 50 1 1 I 103 | X SCS 3 -900 -350 300 R 50 50 1 1 I 104 | X GND 4 -900 -250 300 R 50 50 1 1 I 105 | X RF1 5 -900 -150 300 R 50 50 1 1 I 106 | X RFC 6 -900 -50 300 R 50 50 1 1 I 107 | X GND 7 -900 300 300 R 50 50 1 1 I 108 | X ANT1 8 -900 400 300 R 50 50 1 1 I 109 | X GND 9 -900 500 300 R 50 50 1 1 I 110 | X GND 10 850 500 300 L 50 50 1 1 I 111 | X ANT2 11 850 400 300 L 50 50 1 1 I 112 | X GND 12 850 300 300 L 50 50 1 1 I 113 | X RX/W 13 850 -50 300 L 50 50 1 1 I 114 | X TX/W 14 850 -150 300 L 50 50 1 1 I 115 | X GIO2 15 850 -250 300 L 50 50 1 1 I 116 | X GIO1 16 850 -350 300 L 50 50 1 1 I 117 | X GND 17 850 -450 300 L 50 50 1 1 I 118 | X 3V3 18 850 -550 300 L 50 50 1 1 I 119 | ENDDRAW 120 | ENDDEF 121 | # 122 | # ISP 123 | # 124 | DEF ISP ISP 0 40 Y Y 1 F N 125 | F0 "ISP" 0 350 60 H V C CNN 126 | F1 "ISP" 0 -350 60 H V C CNN 127 | F2 "~" 0 0 60 H V C CNN 128 | F3 "~" 0 0 60 H V C CNN 129 | DRAW 130 | X 1 1 -300 200 300 R 50 50 1 1 B 131 | X 2 2 -300 100 300 R 50 50 1 1 B 132 | X 3 3 -300 0 300 R 50 50 1 1 B 133 | X 4 4 -300 -100 300 R 50 50 1 1 B 134 | X 5 5 -300 -200 300 R 50 50 1 1 B 135 | ENDDRAW 136 | ENDDEF 137 | # 138 | # SMD_CRYSTAL_4PIN 139 | # 140 | DEF SMD_CRYSTAL_4PIN X 0 40 N N 1 F N 141 | F0 "X" 0 150 60 H V C CNN 142 | F1 "SMD_CRYSTAL_4PIN" 0 -150 60 H V C CNN 143 | F2 "~" 0 0 60 H V C CNN 144 | F3 "~" 0 0 60 H V C CNN 145 | DRAW 146 | T 0 -200 50 60 0 0 0 1 Normal 0 C C 147 | T 0 200 50 60 0 0 0 3 Normal 0 C C 148 | S -100 100 -100 -100 0 1 0 N 149 | S -50 100 50 -100 0 1 0 N 150 | S 100 -100 100 -100 0 1 0 N 151 | S 100 100 100 -100 0 1 0 N 152 | X 1 1 -300 0 200 R 40 40 1 1 P 153 | X 3 3 300 0 200 L 40 40 1 1 P 154 | ENDDRAW 155 | ENDDEF 156 | # 157 | # TP 158 | # 159 | DEF ~TP TP 0 40 Y Y 1 F N 160 | F0 "TP" 150 0 60 H V C CNN 161 | F1 "TP" 150 150 60 H I C CNN 162 | F2 "~" 0 0 60 H V C CNN 163 | F3 "~" 0 0 60 H V C CNN 164 | DRAW 165 | C 0 0 71 0 1 0 N 166 | X ~ 1 -300 0 300 R 50 50 1 1 B 167 | ENDDRAW 168 | ENDDEF 169 | # 170 | #End Library 171 | -------------------------------------------------------------------------------- /peripheral_lib/inc/stm32f0xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F0XX_CRC_H 31 | #define __STM32F0XX_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /*!< Includes ----------------------------------------------------------------*/ 38 | #include "stm32f0xx.h" 39 | 40 | /** @addtogroup STM32F0xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_ReverseInputData 52 | * @{ 53 | */ 54 | #define CRC_ReverseInputData_No ((uint32_t)0x00000000) /*!< No reverse operation of Input Data */ 55 | #define CRC_ReverseInputData_8bits CRC_CR_REV_IN_0 /*!< Reverse operation of Input Data on 8 bits */ 56 | #define CRC_ReverseInputData_16bits CRC_CR_REV_IN_1 /*!< Reverse operation of Input Data on 16 bits */ 57 | #define CRC_ReverseInputData_32bits CRC_CR_REV_IN /*!< Reverse operation of Input Data on 32 bits */ 58 | 59 | #define IS_CRC_REVERSE_INPUT_DATA(DATA) (((DATA) == CRC_ReverseInputData_No) || \ 60 | ((DATA) == CRC_ReverseInputData_8bits) || \ 61 | ((DATA) == CRC_ReverseInputData_16bits) || \ 62 | ((DATA) == CRC_ReverseInputData_32bits)) 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup CRC_PolynomialSize 69 | * @brief Only applicable for STM32F042 and STM32F072 devices 70 | * @{ 71 | */ 72 | #define CRC_PolSize_7 CRC_CR_POLSIZE /*!< 7-bit polynomial for CRC calculation */ 73 | #define CRC_PolSize_8 CRC_CR_POLSIZE_1 /*!< 8-bit polynomial for CRC calculation */ 74 | #define CRC_PolSize_16 CRC_CR_POLSIZE_0 /*!< 16-bit polynomial for CRC calculation */ 75 | #define CRC_PolSize_32 ((uint32_t)0x00000000)/*!< 32-bit polynomial for CRC calculation */ 76 | 77 | #define IS_CRC_POL_SIZE(SIZE) (((SIZE) == CRC_PolSize_7) || \ 78 | ((SIZE) == CRC_PolSize_8) || \ 79 | ((SIZE) == CRC_PolSize_16) || \ 80 | ((SIZE) == CRC_PolSize_32)) 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /* Exported macro ------------------------------------------------------------*/ 87 | /* Exported functions ------------------------------------------------------- */ 88 | /* Configuration of the CRC computation unit **********************************/ 89 | void CRC_DeInit(void); 90 | void CRC_ResetDR(void); 91 | void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize); /*!< Only applicable for STM32F042 and STM32F072 devices */ 92 | void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData); 93 | void CRC_ReverseOutputDataCmd(FunctionalState NewState); 94 | void CRC_SetInitRegister(uint32_t CRC_InitValue); 95 | void CRC_SetPolynomial(uint32_t CRC_Pol); /*!< Only applicable for STM32F042 and STM32F072 devices */ 96 | 97 | /* CRC computation ************************************************************/ 98 | uint32_t CRC_CalcCRC(uint32_t CRC_Data); 99 | uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data); /*!< Only applicable for STM32F042 and STM32F072 devices */ 100 | uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data); /*!< Only applicable for STM32F042 and STM32F072 devices */ 101 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 102 | uint32_t CRC_GetCRC(void); 103 | 104 | /* Independent register (IDR) access (write/read) *****************************/ 105 | void CRC_SetIDRegister(uint8_t CRC_IDValue); 106 | uint8_t CRC_GetIDRegister(void); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* __STM32F0XX_CRC_H */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /src/fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 by fishpepper 3 | Copyright (C) 2004 by Steve Karg 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to: 17 | The Free Software Foundation, Inc. 18 | 59 Temple Place - Suite 330 19 | Boston, MA 02111-1307 20 | USA. 21 | 22 | As a special exception, if other files instantiate templates or 23 | use macros or inline functions from this file, or you compile 24 | this file and link it with other works to produce a work based 25 | on this file, this file does not by itself cause the resulting 26 | work to be covered by the GNU General Public License. However 27 | the source code for this file must still be made available in 28 | accordance with section (3) of the GNU General Public License. 29 | 30 | This exception does not invalidate any other reasons why a work 31 | based on this file might be covered by the GNU General Public 32 | License. 33 | */ 34 | 35 | /* Functional Description: Generic FIFO library for deeply 36 | embedded system. See the unit tests for usage examples. */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include "fifo.h" 42 | 43 | /**************************************************************************** 44 | * DESCRIPTION: Returns the number of elements in the ring buffer 45 | * RETURN: Number of elements in the ring buffer 46 | * ALGORITHM: none 47 | * NOTES: none 48 | *****************************************************************************/ 49 | static inline unsigned fifo_count(fifo_buffer_t const *b ) { 50 | return (b ? (b->head - b->tail) : 0); 51 | } 52 | 53 | /**************************************************************************** 54 | * DESCRIPTION: Returns the empty/full status of the ring buffer 55 | * RETURN: true if the ring buffer is full, false if it is not. 56 | * ALGORITHM: none 57 | * NOTES: none 58 | *****************************************************************************/ 59 | static bool fifo_full(fifo_buffer_t const *b) { 60 | return (b ? (fifo_count(b) == b->buffer_len) : true); 61 | } 62 | 63 | /**************************************************************************** 64 | * DESCRIPTION: Returns the empty/full status of the ring buffer 65 | * RETURN: true if the ring buffer is empty, false if it is not. 66 | * ALGORITHM: none 67 | * NOTES: none 68 | *****************************************************************************/ 69 | bool fifo_empty(fifo_buffer_t const *b) { 70 | return (b ? (fifo_count(b) == 0) : true); 71 | } 72 | 73 | /**************************************************************************** 74 | * DESCRIPTION: Looks at the data from the head of the list without removing it 75 | * RETURN: byte of data, or zero if nothing in the list 76 | * ALGORITHM: none 77 | * NOTES: Use Empty function to see if there is data to retrieve 78 | *****************************************************************************/ 79 | uint8_t fifo_peek(fifo_buffer_t const *b) { 80 | if (b) { 81 | return (b->buffer[b->tail % b->buffer_len]); 82 | } 83 | 84 | return 0; 85 | } 86 | 87 | /**************************************************************************** 88 | * DESCRIPTION: Gets the data from the front of the list, and removes it 89 | * RETURN: the data, or zero if nothing in the list 90 | * ALGORITHM: none 91 | * NOTES: Use Empty function to see if there is data to retrieve 92 | *****************************************************************************/ 93 | uint8_t fifo_get(fifo_buffer_t * b) { 94 | uint8_t data_byte = 0; 95 | 96 | if (!fifo_empty(b)) { 97 | data_byte = b->buffer[b->tail % b->buffer_len]; 98 | b->tail++; 99 | } 100 | return data_byte; 101 | } 102 | 103 | /**************************************************************************** 104 | * DESCRIPTION: Adds an element of data to the FIFO 105 | * RETURN: true on succesful add, false if not added 106 | * ALGORITHM: none 107 | * NOTES: none 108 | *****************************************************************************/ 109 | bool fifo_put(fifo_buffer_t * b, uint8_t data_byte) { 110 | bool status = false; /* return value */ 111 | 112 | if (b) { 113 | /* limit the ring to prevent overwriting */ 114 | if (!fifo_full(b)) { 115 | b->buffer[b->head % b->buffer_len] = data_byte; 116 | b->head++; 117 | status = true; 118 | } 119 | } 120 | 121 | return status; 122 | } 123 | 124 | /**************************************************************************** 125 | * DESCRIPTION: Configures the ring buffer 126 | * RETURN: none 127 | * ALGORITHM: none 128 | * NOTES: buffer_len must be a power of two 129 | *****************************************************************************/ 130 | void fifo_init(fifo_buffer_t * b, volatile uint8_t *buffer, unsigned buffer_len) { 131 | if (b) { 132 | b->head = 0; 133 | b->tail = 0; 134 | b->buffer = buffer; 135 | b->buffer_len = buffer_len; 136 | } 137 | 138 | return; 139 | } 140 | -------------------------------------------------------------------------------- /src/eeprom.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | 21 | #include "eeprom.h" 22 | #include "debug.h" 23 | #include "delay.h" 24 | #include "storage.h" 25 | 26 | #include 27 | #include 28 | 29 | // init for st eeprom emulation, set up number of variables. 30 | uint16_t EE_virtual_address_table[EE_NB_OF_VAR]; 31 | 32 | #include "eeprom_emulation/st_eeprom.h" 33 | 34 | void eeprom_init(void) { 35 | debug("eeprom: init\n"); debug_flush(); 36 | 37 | // initialize virtual adresses 38 | uint32_t i; 39 | for (i = 0; i < EE_NB_OF_VAR; i++) { 40 | EE_virtual_address_table[i] = i; 41 | } 42 | 43 | // unlock flash for writing 44 | flash_unlock(); 45 | 46 | // initialise eeprom emulation 47 | uint16_t res = EE_Init(); 48 | 49 | if (res != FLASH_COMPLETE) { 50 | debug("eeprom: EE_init failed: 0x"); 51 | debug_put_hex16(res); 52 | debug_put_newline(); 53 | debug_flush(); 54 | } 55 | 56 | // lock flash again 57 | flash_lock(); 58 | } 59 | 60 | void eeprom_write_storage(void) { 61 | debug("eeprom: writing storage\n"); debug_flush(); 62 | uint8_t *storage_ptr; 63 | uint16_t p = 0; 64 | uint16_t i; 65 | 66 | storage_ptr = (uint8_t*)&storage; 67 | 68 | /*debug("eeprom: storing "); debug_put_uint16(sizeof(storage)); 69 | debug("b\n"); 70 | debug("in "); debug_put_uint16(EE_NB_OF_VAR); 71 | debug(" 16b entries.");*/ 72 | flash_unlock(); 73 | for (i = 0; i < EE_NB_OF_VAR; i++) { 74 | // fetch current value. make sure that out of bound access to storage reads as zero 75 | uint16_t value_now = 0; 76 | if (p < sizeof (storage)) value_now = storage_ptr[p++] << 8; 77 | if (p < sizeof (storage)) value_now |= storage_ptr[p++]; 78 | 79 | /*debug("storage: wr 0x"); 80 | if ((p-2) < sizeof(storage)) { debug_put_hex8(storage_ptr[p-2]); } else { debug("--");} 81 | debug(" 0x"); 82 | if ((p-1) < sizeof(storage)) { debug_put_hex8(storage_ptr[p-1]); } else { debug("--");} 83 | debug("\n-> combined to 0x"); 84 | debug_put_hex16(value_now); 85 | debug_put_newline(); 86 | debug_flush(); 87 | if (i == 0) delay_ms(5000);*/ 88 | 89 | // fetch value from eeprom in order to check for a change 90 | uint16_t value_ee; 91 | uint16_t res = EE_ReadVariable(EE_virtual_address_table[i], &value_ee); 92 | 93 | /*if (res != 0) { 94 | debug("eeprom: fetch failed for 0x"); 95 | debug_put_hex16(i); 96 | debug_put_newline(); 97 | debug_flush(); 98 | }*/ 99 | 100 | if (value_now != value_ee) { 101 | debug("eeprom: val["); debug_put_hex16(i); debug("] modified\n"); 102 | res = EE_WriteVariable(EE_virtual_address_table[i], value_now); 103 | if (res != FLASH_COMPLETE) { 104 | debug("eeprom: write failed for 0x"); 105 | debug_put_hex16(i); 106 | debug_put_newline(); 107 | debug_flush(); 108 | } 109 | } 110 | } 111 | flash_lock(); 112 | // uint32_t t; for (t = 0; t < 20; t++) { delay_ms(100); wdt_reset(); } 113 | } 114 | 115 | 116 | void eeprom_read_storage(void) { 117 | debug("eeprom: reading storage\n"); debug_flush(); 118 | uint8_t *storage_ptr; 119 | uint16_t p = 0; 120 | uint16_t i; 121 | 122 | // pointer to persistant storage 123 | storage_ptr = (uint8_t*)&storage; 124 | 125 | // invalidate storage 126 | storage.version = 0; 127 | 128 | flash_unlock(); 129 | for (i = 0; i < EE_NB_OF_VAR; i++) { 130 | // fetch current 16bit value 131 | uint16_t value; 132 | 133 | // fetch value from eeprom in order to check for a change 134 | uint16_t res = EE_ReadVariable(EE_virtual_address_table[i], &value); 135 | 136 | if (res != 0) { 137 | /*debug("eeprom: fetch failed for 0x"); 138 | debug_put_hex16(i); 139 | debug_put_newline(); 140 | debug_flush();*/ 141 | } else { 142 | /*debug("eeprom: read 0x"); debug_put_hex16(value); debug_put_newline(); debug_flush(); 143 | delay_ms(100);*/ 144 | 145 | // read back into storage: 146 | if (p < sizeof (storage)) storage_ptr[p++] = (value>>8) & 0xFF; 147 | if (p < sizeof (storage)) storage_ptr[p++] = value & 0xFF; 148 | 149 | /*if (i == 0) { 150 | debug("eeprom: 0x"); debug_put_hex8(storage_ptr[0]); 151 | debug(" 0x"); debug_put_hex8(storage_ptr[1]); debug_put_newline(); 152 | debug("s.v = 0x"); debug_put_hex8(storage.version); 153 | debug_put_newline(); debug_flush(); 154 | delay_ms(5000); 155 | }*/ 156 | } 157 | } 158 | // debug_put_hex16(storage.checksum); 159 | flash_lock(); 160 | // uint32_t t; for (t = 0; t < 20; t++) { delay_ms(100); wdt_reset(); } 161 | } 162 | 163 | 164 | -------------------------------------------------------------------------------- /src/sound.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | 21 | #include "sound.h" 22 | #include "config.h" 23 | #include "debug.h" 24 | #include "delay.h" 25 | #include "clocksource.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | // internal static functions 32 | static void sound_init_rcc(void); 33 | static void sound_init_gpio(void); 34 | 35 | 36 | #define SOUND_QUEUE_SIZE 10 37 | volatile __IO uint32_t sound_tone_duration; 38 | static tone_t sound_queue[SOUND_QUEUE_SIZE]; 39 | uint32_t sound_queue_state; 40 | 41 | 42 | void sound_init(void) { 43 | debug("sound: init\n"); debug_flush(); 44 | sound_init_rcc(); 45 | sound_init_gpio(); 46 | 47 | sound_queue_state = 0; 48 | sound_set_frequency(0); 49 | /* 50 | sound_queue[0].frequency = 500; 51 | sound_queue[0].duration_ms = 8000; 52 | sound_queue[1].frequency = 890; 53 | sound_queue[1].duration_ms = 80; 54 | sound_queue[2].frequency = 1000; 55 | sound_queue[2].duration_ms = 8000; 56 | sound_queue[3].frequency = 0; 57 | sound_queue[3].duration_ms = 0; 58 | sound_queue_state = 1; 59 | */ 60 | sound_tone_duration = 0; 61 | } 62 | 63 | void sound_play_bind(void) { 64 | sound_queue[0].frequency = 2000; 65 | sound_queue[0].duration_ms = 100; 66 | sound_queue[1].frequency = 1000; 67 | sound_queue[1].duration_ms = 100; 68 | sound_queue[2].duration_ms = 0; 69 | sound_queue_state = 1; 70 | } 71 | 72 | void sound_play_click(void) { 73 | sound_queue[0].frequency = 20000; 74 | sound_queue[0].duration_ms = 80; 75 | sound_queue[1].duration_ms = 0; 76 | sound_queue_state = 1; 77 | } 78 | 79 | void sound_play_low_time(void) { 80 | sound_queue[0].frequency = 4000; 81 | sound_queue[0].duration_ms = 300; 82 | sound_queue[1].duration_ms = 0; 83 | sound_queue_state = 1; 84 | } 85 | 86 | static void sound_init_rcc(void) { 87 | // enable peripheral clock 88 | rcc_periph_clock_enable(GPIO_RCC(SPEAKER_GPIO)); 89 | 90 | // timer1 clock 91 | rcc_periph_clock_enable(RCC_TIM1); 92 | } 93 | 94 | static void sound_init_gpio(void) { 95 | // set all gpio directions to output 96 | gpio_mode_setup(SPEAKER_GPIO, GPIO_MODE_AF, GPIO_PUPD_NONE, SPEAKER_PIN); 97 | gpio_set_output_options(SPEAKER_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, SPEAKER_PIN); 98 | 99 | // connect TIM1 pins to AF2 on gpio 100 | gpio_set_af(SPEAKER_GPIO, GPIO_AF2, SPEAKER_PIN); 101 | } 102 | 103 | void sound_set_frequency(uint32_t freq) { 104 | uint32_t prescaler, period; 105 | 106 | if (freq <= 200) { 107 | // switch off pwm 108 | timer_disable_oc_output(TIM1, TIM_OC1); 109 | // return; 110 | } 111 | 112 | // reset TIMx peripheral 113 | timer_reset(TIM1); 114 | 115 | // roughly factor into 16-bit 116 | period = (rcc_timer_frequency / 1) / freq; 117 | prescaler = (period / 65536) + 1; 118 | period = (period / prescaler); 119 | 120 | // Set the timers global mode to: 121 | // - use no divider 122 | // - alignment edge 123 | // - count direction up 124 | timer_set_mode(TIM1, 125 | TIM_CR1_CKD_CK_INT, 126 | TIM_CR1_CMS_EDGE, 127 | TIM_CR1_DIR_UP); 128 | 129 | timer_set_prescaler(TIM1, prescaler - 1); 130 | timer_set_repetition_counter(TIM1, 0); 131 | 132 | timer_enable_preload(TIM1); 133 | timer_continuous_mode(TIM1); 134 | timer_set_period(TIM1, period - 1); 135 | 136 | // start with disabled pwm output 137 | timer_disable_oc_output(TIM1, TIM_OC1); 138 | 139 | // NOTE: on advanced timers as TIM1 we have 140 | // to break the main output, otherwise 141 | // no pwm output signal will be present on pin 142 | timer_enable_break_main_output(TIM1); 143 | 144 | // configure output mode 145 | timer_set_oc_mode(TIM1, TIM_OC1, TIM_OCM_PWM1); 146 | // set period for 50/50 duty cycle 147 | timer_set_oc_value(TIM1, TIM_OC1, period / 2); 148 | // enable pwm output 149 | timer_enable_oc_output(TIM1, TIM_OC1); 150 | 151 | // start timer 152 | timer_enable_counter(TIM1); 153 | } 154 | 155 | void sound_play_sample(tone_t *tone) { 156 | uint8_t i; 157 | // add this sound sample to the playback queue: 158 | for (i = 0; i < SOUND_QUEUE_SIZE; i++) { 159 | sound_queue[i] = *tone; 160 | if ((tone->duration_ms == 0) && (tone->frequency == 0)) { 161 | // done, this was the last sample 162 | break; 163 | } else { 164 | tone++; 165 | } 166 | } 167 | sound_queue_state = 0; 168 | } 169 | 170 | void sound_handle_playback(void) { 171 | if (sound_queue_state == 0) { 172 | // off, return 173 | return; 174 | } 175 | 176 | if (sound_tone_duration == 0) { 177 | // next sample 178 | uint32_t id = sound_queue_state - 1; 179 | if ((id == SOUND_QUEUE_SIZE) || (sound_queue[id].duration_ms == 0)) { 180 | // no more samples, switch off: 181 | sound_set_frequency(0); 182 | sound_queue_state = 0; 183 | } else { 184 | // fetch next sample 185 | sound_tone_duration = 10*sound_queue[id].duration_ms; 186 | sound_set_frequency(sound_queue[id].frequency); 187 | sound_queue_state++; 188 | } 189 | 190 | } else { 191 | sound_tone_duration--; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "main.h" 21 | #include "clocksource.h" 22 | #include "timeout.h" 23 | #include "config.h" 24 | #include "delay.h" 25 | #include "sound.h" 26 | #include "led.h" 27 | #include "io.h" 28 | #include "lcd.h" 29 | #include "debug.h" 30 | #include "screen.h" 31 | #include "console.h" 32 | #include "adc.h" 33 | #include "sound.h" 34 | #include "touch.h" 35 | #include "cc2500.h" 36 | #include "frsky.h" 37 | #include "storage.h" 38 | #include "wdt.h" 39 | #include "gui.h" 40 | #include "eeprom.h" 41 | #include "usb.h" 42 | 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | 49 | // Define our function pointer 50 | void (*bootloader_jump)(void); 51 | 52 | static void handle_bootloader_request(void) { 53 | // Check if we should go into bootloader mode. 54 | // 55 | // Set the main stack pointer __set_MSP() to its default value. The default 56 | // value of the main stack pointer is found by looking at the default value 57 | // in the System Memory start address. Do this in IAR View -> Memory. I 58 | // tried this and it showed address: 0x200014A8 which I then tried here. 59 | // The IAR compiler complained that it was out of range. After some 60 | // research, I found the following from "The STM32 Cortex-M0 Programming 61 | // Manual": 62 | // Main Stack Pointer (MSP)(reset value). On reset, the processor 63 | // loads the MSP with the value from address 0x00000000. 64 | // 65 | // So I then looked at the default value at address 0x0 and it was 0x20002250 66 | // 67 | // Note that 0x1fffC800 is "System Memory" start address for STM32 F0xx 68 | // 69 | if ( *((uint32_t *)0x20003FF0) == 0xDEADBEEF ) { 70 | *((uint32_t *)0x20003FF0) = 0xCAFEFEED; // Reset our trigger 71 | // 0x1fffC800 is "System Memory" start address for STM32 F0xx 72 | // point the PC to the System Memory reset vector (+4) 73 | bootloader_jump = (void (*)(void)) (*((uint32_t *) 0x1fffC804)); 74 | bootloader_jump(); 75 | while (1) {} 76 | } 77 | } 78 | 79 | #ifdef USB_ENABLED 80 | 81 | int main(void) { 82 | rcc_clock_setup_in_hsi_out_48mhz(); 83 | 84 | rcc_periph_clock_enable(RCC_GPIOA); 85 | /* 86 | * This is a somewhat common cheap hack to trigger device re-enumeration 87 | * on startup. Assuming a fixed external pullup on D+, (For USB-FS) 88 | * setting the pin to output, and driving it explicitly low effectively 89 | * "removes" the pullup. The subsequent USB init will "take over" the 90 | * pin, and it will appear as a proper pullup to the host. 91 | * The magic delay is somewhat arbitrary, no guarantees on USBIF 92 | * compliance here, but "it works" in most places. 93 | */ 94 | // set led pin as output 95 | gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12); 96 | gpio_set_output_options(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO12); 97 | gpio_clear(GPIOA, GPIO12); 98 | 99 | for (unsigned i = 0; i < 800000; i++) { 100 | __asm__("nop"); 101 | } 102 | 103 | usbd_dev = usbd_init(&st_usbfs_v2_usb_driver, &dev_descr, 104 | &config, usb_strings, 3, usbd_control_buffer, sizeof(usbd_control_buffer)); 105 | usbd_register_set_config_callback(usbd_dev, hid_set_config); 106 | 107 | while (1) 108 | usbd_poll(usbd_dev); 109 | } 110 | 111 | void sys_tick_handler(void) { 112 | /*static int x = 0; 113 | static int dir = 1; 114 | uint8_t buf[4] = {0, 0, 0, 0}; 115 | 116 | buf[1] = dir; 117 | x += dir; 118 | if (x > 30) 119 | dir = -dir; 120 | if (x < -30) 121 | dir = -dir; 122 | 123 | usbd_ep_write_packet(usbd_dev, 0x81, buf, 4);*/ 124 | static uint16_t adc_data = 0; 125 | static uint8_t buf[1 + 16]; 126 | static uint8_t channels[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; 127 | 128 | for (unsigned int i = 0; i < 8; i++) { 129 | uint16_t res = adc_data++; 130 | buf[1 + i * 2] = res & 0xff; 131 | buf[1 + i * 2 + 1] = res >> 8; 132 | } 133 | 134 | buf[0] = 0; // adc_data~(gpio_get(GPIOB, BUTTONS_PINS) >> BUTTONS_SHIFT); 135 | usbd_ep_write_packet(usbd_dev, 0x81, buf, sizeof(buf)); 136 | } 137 | 138 | 139 | 140 | 141 | #else 142 | int main(void) { 143 | // if this was a reboot with bootloader request enter 144 | // internal rom bootloader 145 | handle_bootloader_request(); 146 | 147 | // init crystal osc & set clock options 148 | clocksource_init(); 149 | 150 | 151 | config_init(); 152 | 153 | delay_init(); 154 | 155 | 156 | led_init(); 157 | 158 | 159 | // wdt_init(); 160 | 161 | io_init(); 162 | timeout_init(); 163 | 164 | 165 | lcd_init(); 166 | 167 | 168 | lcd_show_logo(); 169 | screen_init(); 170 | 171 | 172 | console_init(); 173 | 174 | 175 | debug_init(); 176 | 177 | 178 | adc_init(); 179 | sound_init(); 180 | 181 | 182 | touch_init(); 183 | eeprom_init(); 184 | storage_init(); 185 | 186 | frsky_init(); 187 | 188 | usb_init(); 189 | 190 | /// screen_test(); 191 | // touch_test(); 192 | // adc_test(); 193 | gui_init(); 194 | 195 | 196 | debug("main: init done.\n"); debug_flush(); 197 | 198 | gui_loop(); 199 | 200 | while (1) { 201 | // adc_test(); 202 | // io_powerdown_test(); 203 | // debug("ABCDEFGHIJKLMN\ni . !\n"); debug_flush(); 204 | // while (1); 205 | // 206 | } 207 | } 208 | 209 | #endif // 0 210 | -------------------------------------------------------------------------------- /src/fonts/metric7x12.h: -------------------------------------------------------------------------------- 1 | /* 2 | Based on the "Metric" font from https://saelaenx.wordpress.com 3 | Converted for GLCD format by Christian Isenberg 4 | 27/09/2015 5 | */ 6 | 7 | #ifndef __FONT_METRIC7x12_H__ 8 | #define __FONT_METRIC7x12_H__ 9 | 10 | #include 11 | 12 | // font data 13 | const uint8_t font_metric7x12[] = { 14 | 0x0, 0x0, // size of zero indicates fixed width font 15 | 7, // width 16 | 12, // height 17 | 32, // first char (space) 18 | 94, // char count 19 | 20 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // space 21 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 22 | 23 | 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, // ! 24 | 0x0, 0x0, 0xc, 0xc, 0x0, 0x0, 0x0, 25 | 26 | 0x0, 0x0, 0x3, 0x0, 0x3, 0x0, 0x0, // " 27 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 28 | 29 | 0x6, 0xff, 0xff, 0x6, 0xff, 0xff, 0x6, // # 30 | 0x3, 0xf, 0xf, 0x3, 0xf, 0xf, 0x3, 31 | 32 | 0x3c, 0x7e, 0x66, 0xff, 0x66, 0xe6, 0xc6, // $ 33 | 0x6, 0x6, 0x6, 0xf, 0x6, 0x7, 0x3, 34 | 35 | 0x7, 0x5, 0xc7, 0xf0, 0x3c, 0xf, 0x3, // % 36 | 0xc, 0xf, 0x3, 0x0, 0xe, 0xa, 0xe, 37 | 38 | 0x9e, 0xff, 0x63, 0xff, 0xfe, 0x60, 0x60, // & 39 | 0x7, 0xf, 0x8, 0xf, 0x7, 0xe, 0xc, 40 | 41 | 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, // ' 42 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 43 | 44 | 0x0, 0xf0, 0xfe, 0xf, 0x3, 0x0, 0x0, // ( 45 | 0x0, 0x0, 0x3, 0xf, 0xc, 0x0, 0x0, 46 | 47 | 0x0, 0x0, 0x3, 0xf, 0xfe, 0xf0, 0x0, // ) 48 | 0x0, 0x0, 0xc, 0xf, 0x7, 0x0, 0x0, 49 | 50 | 0x7, 0x5, 0x7, 0x0, 0x0, 0x0, 0x0, // * 51 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 52 | 53 | 0x0, 0x20, 0x20, 0xf8, 0x20, 0x20, 0x0, // + 54 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 55 | 56 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // , 57 | 0x0, 0x0, 0x8, 0x4, 0x0, 0x0, 0x0, 58 | 59 | 0x0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x0, // - 60 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 61 | 62 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // . 63 | 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 64 | 65 | 0x0, 0x0, 0xc0, 0xf0, 0x3c, 0xf, 0x3, // / 66 | 0xc, 0xf, 0x3, 0x0, 0x0, 0x0, 0x0, 67 | 68 | 0xfe, 0xff, 0x3, 0x3, 0x3, 0xff, 0xfe, // 0 69 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 70 | 71 | 0x0, 0x3, 0x3, 0xff, 0xfe, 0x0, 0x0, // 1 72 | 0xc, 0xc, 0xc, 0xf, 0xf, 0xc, 0xc, 73 | 74 | 0xc3, 0xe3, 0x63, 0x63, 0x63, 0x7f, 0x7e, // 2 75 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xc, 0xc, 76 | 77 | 0x3, 0x63, 0x63, 0x63, 0x63, 0xff, 0xfe, // 3 78 | 0xc, 0xc, 0xc, 0xc, 0xc, 0xf, 0x7, 79 | 80 | 0x3f, 0x7f, 0x60, 0x60, 0x60, 0xff, 0xff, // 4 81 | 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 82 | 83 | 0x3e, 0x7f, 0x63, 0x63, 0x63, 0xe3, 0xc3, // 5 84 | 0xc, 0xc, 0xc, 0xc, 0xc, 0xf, 0x7, 85 | 86 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0xe3, 0xc3, // 6 87 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 88 | 89 | 0x3, 0x3, 0x3, 0x3, 0x3, 0xff, 0xfe, // 7 90 | 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 91 | 92 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0xff, 0xfe, // 8 93 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 94 | 95 | 0x3e, 0x7f, 0x63, 0x63, 0x63, 0xff, 0xfe, // 9 96 | 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 97 | 98 | 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, // : 99 | 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 100 | 101 | 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, // ; 102 | 0x0, 0x0, 0x8, 0x4, 0x0, 0x0, 0x0, 103 | 104 | 0x60, 0xf0, 0x98, 0xc, 0x6, 0x3, 0x3, // < 105 | 0x0, 0x0, 0x1, 0x3, 0x6, 0xc, 0xc, 106 | 107 | 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, // = 108 | 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 109 | 110 | 0x3, 0x3, 0x6, 0xc, 0x98, 0xf0, 0x60, // > 111 | 0xc, 0xc, 0x6, 0x3, 0x1, 0x0, 0x0, 112 | 113 | 0x3, 0x3, 0xc3, 0xe3, 0x63, 0x7f, 0x3e, // ? 114 | 0x0, 0x0, 0xc, 0xc, 0x0, 0x0, 0x0, 115 | 116 | 0xfe, 0xff, 0x3, 0xe3, 0xc3, 0xff, 0x7e, // @ 117 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xc, 0xc, 118 | 119 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0xff, 0xfe, // A 120 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 121 | 122 | 0xff, 0xff, 0x63, 0x63, 0x63, 0xff, 0x9e, // B 123 | 0xf, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 124 | 125 | 0xfe, 0xff, 0x3, 0x3, 0x3, 0x3, 0x3, // C 126 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xc, 0xc, 127 | 128 | 0xff, 0xff, 0x3, 0x3, 0x3, 0xff, 0xfe, // D 129 | 0xf, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 130 | 131 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0x63, 0x3, // E 132 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xc, 0xc, 133 | 134 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0x63, 0x3, // F 135 | 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 136 | 137 | 0xfe, 0xff, 0x3, 0x3, 0x63, 0xe3, 0xe0, // G 138 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 139 | 140 | 0xff, 0xff, 0x60, 0x60, 0x60, 0xff, 0xff, // H 141 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 142 | 143 | 0x3, 0x3, 0x3, 0xff, 0xff, 0x3, 0x3, // I 144 | 0xc, 0xc, 0xc, 0xf, 0xf, 0xc, 0xc, 145 | 146 | 0x0, 0x3, 0x3, 0x3, 0x3, 0xff, 0xff, // J 147 | 0xc, 0xc, 0xc, 0xc, 0xc, 0xf, 0x7, 148 | 149 | 0xff, 0xff, 0x60, 0x60, 0x60, 0xff, 0x9f, // K 150 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 151 | 152 | 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, // L 153 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xc, 0xc, 154 | 155 | 0xfe, 0xff, 0x3, 0x6, 0x3, 0xff, 0xfe, // M 156 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 157 | 158 | 0xfe, 0xff, 0x3, 0x3, 0x3, 0xff, 0xfe, // N 159 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 160 | 161 | 0xfe, 0xff, 0x3, 0x3, 0x3, 0xff, 0xfe, // O 162 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 163 | 164 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0x7f, 0x3e, // P 165 | 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 166 | 167 | 0xfe, 0xff, 0x3, 0x3, 0x3, 0xff, 0xfe, // Q 168 | 0x7, 0xf, 0xc, 0xf, 0xc, 0xf, 0x7, 169 | 170 | 0xfe, 0xff, 0x63, 0x63, 0x63, 0xff, 0x9e, // R 171 | 0xf, 0xf, 0x0, 0x0, 0x0, 0xf, 0xf, 172 | 173 | 0x3e, 0x7f, 0x63, 0x63, 0x63, 0xe3, 0xc3, // S 174 | 0xc, 0xc, 0xc, 0xc, 0xc, 0xf, 0x7, 175 | 176 | 0x3, 0x3, 0x3, 0xff, 0xff, 0x3, 0x3, // T 177 | 0x0, 0x0, 0x0, 0xf, 0xf, 0x0, 0x0, 178 | 179 | 0xff, 0xff, 0x0, 0x0, 0x0, 0xff, 0xff, // U 180 | 0x7, 0xf, 0xc, 0xc, 0xc, 0xf, 0x7, 181 | 182 | 0xff, 0xff, 0x80, 0x0, 0x80, 0xff, 0xff, // V 183 | 0x0, 0x1, 0x7, 0xe, 0x7, 0x1, 0x0, 184 | 185 | 0xff, 0xff, 0x0, 0x0, 0x0, 0xff, 0xff, // W 186 | 0x7, 0xf, 0xc, 0x6, 0xc, 0xf, 0xf, 187 | 188 | 0x3, 0xf, 0xfc, 0xf8, 0xfc, 0xf, 0x3, // X 189 | 0xc, 0xf, 0x3, 0x0, 0x3, 0xf, 0xc, 190 | 191 | 0x3f, 0x7f, 0x60, 0x60, 0x60, 0xff, 0xff, // Y 192 | 0xc, 0xc, 0xc, 0xc, 0xc, 0xf, 0x7, 193 | 194 | 0x3, 0x3, 0xc3, 0xf3, 0x3f, 0xf, 0x3, // Z 195 | 0xc, 0xf, 0xf, 0xc, 0xc, 0xc, 0xc, 196 | 197 | 0xff, 0xff, 0x3, 0x3, 0x0, 0x0, 0x0, // [ 198 | 0xf, 0xf, 0xc, 0xc, 0x0, 0x0, 0x0, 199 | 200 | 0x3, 0xf, 0x3c, 0xf0, 0xc0, 0x0, 0x0, // "\" 201 | 0x0, 0x0, 0x0, 0x0, 0x3, 0xf, 0xc, 202 | 203 | 0x0, 0x0, 0x0, 0x3, 0x3, 0xff, 0xff, // ] 204 | 0x0, 0x0, 0x0, 0xc, 0xc, 0xf, 0xf, 205 | 206 | 0x60, 0x78, 0x1e, 0x7, 0x1e, 0x78, 0x60, // ^ 207 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 208 | 209 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // _ 210 | 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 211 | 212 | 0x0, 0x0, 0x1, 0x2, 0x0, 0x0, 0x0, // ` 213 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 214 | 215 | }; 216 | #endif 217 | 218 | -------------------------------------------------------------------------------- /src/storage.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "storage.h" 21 | #include "debug.h" 22 | #include "wdt.h" 23 | #include "delay.h" 24 | #include "led.h" 25 | #include "frsky.h" 26 | #include "eeprom.h" 27 | #include "hoptable.h" 28 | #include "crc16.h" 29 | 30 | // internal functions 31 | static uint8_t storage_is_valid(void); 32 | static uint16_t storage_calc_crc(void); 33 | static void storage_load_defaults(void); 34 | 35 | 36 | // run time copy of persistant storage data: 37 | STORAGE_DESC storage; 38 | 39 | void storage_init(void) { 40 | uint8_t i; 41 | 42 | debug("storage: init\n"); debug_flush(); 43 | 44 | 45 | // reload data from flash 46 | storage_load(); 47 | 48 | if (!storage_is_valid()) { 49 | // bad storage -> re init! 50 | storage_load_defaults(); 51 | storage_save(); 52 | // reload to make sure write was ok 53 | storage_load(); 54 | } 55 | 56 | // for debugging 57 | // storage_load_defaults(); 58 | // storage_save(); 59 | 60 | debug("storage: loaded hoptable[]:\n"); 61 | for (i = 0; i < 9; i++) { 62 | debug_put_hex8(storage.frsky_hop_table[i]); 63 | debug_putc(' '); 64 | } 65 | 66 | debug("...\n"); 67 | debug("storage: txid 0x"); 68 | debug_put_hex8(storage.frsky_txid[0]); 69 | debug_put_hex8(storage.frsky_txid[1]); 70 | debug_flush(); 71 | 72 | debug("\nstorage: stick calib:\n"); 73 | for (i = 0; i < 4; i++) { 74 | debug("CH "); debug_put_uint8(i); debug_putc(' '); 75 | debug_put_uint16(storage.stick_calibration[i][0]); debug_putc('-'); 76 | debug_put_uint16(storage.stick_calibration[i][1]); debug_putc('-'); 77 | debug_put_uint16(storage.stick_calibration[i][2]); 78 | debug_put_newline(); 79 | } 80 | debug_flush(); 81 | } 82 | 83 | static uint8_t storage_is_valid(void) { 84 | uint16_t crc; 85 | 86 | // first of all check revision: 87 | if (storage.version != STORAGE_VERSION_ID) { 88 | debug("storage: corrupted! bad version\n"); 89 | debug("got 0x"); 90 | debug_put_hex8(storage.version); 91 | debug_put_newline(); 92 | debug_flush(); 93 | return 0; 94 | } 95 | 96 | // verify checksum: 97 | crc = storage_calc_crc(); 98 | if (storage.checksum != crc) { 99 | debug("storage: crc error: 0x"); 100 | debug_put_hex16(storage.checksum); 101 | debug("\ngot 0x"); 102 | debug_put_hex16(crc); 103 | debug("instead\n"); 104 | debug_flush(); 105 | return 0; 106 | } 107 | 108 | // fine 109 | return 1; 110 | } 111 | 112 | static uint16_t storage_calc_crc(void) { 113 | uint16_t crc; 114 | uint8_t *storage_ptr; 115 | 116 | // calc pointer to storage mem 117 | storage_ptr = (uint8_t*)&storage; 118 | 119 | // calc crc16 over data (without checksum): 120 | crc = crc16(storage_ptr, sizeof(storage) - sizeof(storage.checksum)); 121 | 122 | // return result 123 | return crc; 124 | } 125 | 126 | static void storage_load_defaults(void) { 127 | uint8_t i; 128 | 129 | debug("storage: reading defaults\n"); debug_flush(); 130 | 131 | static const uint8_t tmp[] = FRSKY_HOPTABLE; 132 | 133 | // set valid version 134 | storage.version = STORAGE_VERSION_ID; 135 | 136 | // load values from .hoptable.h 137 | storage.frsky_txid[0] = (FRSYK_TXID>>8) & 0xFF; 138 | storage.frsky_txid[1] = FRSYK_TXID & 0xFF; 139 | 140 | storage.frsky_freq_offset = FRSKY_DEFAULT_FSCAL_VALUE; 141 | 142 | // copy hoptable 143 | for (i = 0; i < FRSKY_HOPTABLE_SIZE; i++) { 144 | storage.frsky_hop_table[i] = tmp[i]; 145 | } 146 | 147 | // stick calib, just dummy values 148 | for (i = 0; i < 4; i++) { 149 | storage.stick_calibration[i][0] = 300; 150 | storage.stick_calibration[i][1] = 2000; 151 | storage.stick_calibration[i][2] = 4096-300; 152 | } 153 | 154 | // initialise empty models 155 | for (i = 0; i < STORAGE_MODEL_MAX_COUNT; i++) { 156 | storage.model[i].name[0] = 'E'; 157 | storage.model[i].name[1] = 'M'; 158 | storage.model[i].name[2] = 'P'; 159 | storage.model[i].name[3] = 'T'; 160 | storage.model[i].name[4] = 'Y'; 161 | storage.model[i].name[5] = '0' + i; 162 | storage.model[i].name[6] = 0; 163 | storage.model[i].timer = 3*60; 164 | storage.model[i].stick_scale = 100; 165 | } 166 | 167 | // add example model 168 | storage_mode_set_name(0, "TinyWhoop"); 169 | storage.model[0].timer = 3*60; 170 | storage.model[i].stick_scale = 50; 171 | storage.current_model = 0; 172 | } 173 | 174 | void storage_mode_set_name(uint8_t index, char *str) { 175 | debug("storage: set modelname "); 176 | debug_put_uint8(index); 177 | debug("\n "); 178 | debug(str); 179 | debug_put_newline(); 180 | debug_flush(); 181 | 182 | // valid index? 183 | if (index >= STORAGE_MODEL_MAX_COUNT) { 184 | // invalid index! 185 | debug("storage: ERROR invalid index\n"); 186 | debug_flush(); 187 | return; 188 | } 189 | 190 | // make sure not to exceed the maximum number of chars in name 191 | uint32_t i; 192 | for (i = 0; i < STORAGE_MODEL_NAME_LEN; i++) { 193 | storage.model[index].name[i] = str[i]; 194 | if (str[i] == 0) { 195 | break; 196 | } 197 | } 198 | 199 | // make sure we have a valid zero terminated string in any case 200 | storage.model[index].name[STORAGE_MODEL_NAME_LEN-1] = 0; 201 | } 202 | 203 | void storage_load(void) { 204 | debug("storage: load\n"); debug_flush(); 205 | eeprom_read_storage(); 206 | } 207 | 208 | void storage_save(void) { 209 | debug("storage: save\n"); debug_flush(); 210 | 211 | // store the current crc for the storage 212 | storage.checksum = storage_calc_crc(); 213 | 214 | // and finally write it to eeprom 215 | eeprom_write_storage(); 216 | } 217 | -------------------------------------------------------------------------------- /peripheral_lib/src/stm32f0xx_misc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_misc.c 4 | * @author MCD Application Team 5 | * @version V1.5.0 6 | * @date 05-December-2014 7 | * @brief This file provides all the miscellaneous firmware functions (add-on 8 | * to CMSIS functions). 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f0xx_misc.h" 31 | 32 | /** @addtogroup STM32F0xx_StdPeriph_Driver 33 | * @{ 34 | */ 35 | 36 | /** @defgroup MISC 37 | * @brief MISC driver modules 38 | * @{ 39 | */ 40 | 41 | /* Private typedef -----------------------------------------------------------*/ 42 | /* Private define ------------------------------------------------------------*/ 43 | /* Private macro -------------------------------------------------------------*/ 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* Private function prototypes -----------------------------------------------*/ 46 | /* Private functions ---------------------------------------------------------*/ 47 | 48 | /** @defgroup MISC_Private_Functions 49 | * @{ 50 | */ 51 | /** 52 | * 53 | @verbatim 54 | ******************************************************************************* 55 | ##### Interrupts configuration functions ##### 56 | ******************************************************************************* 57 | [..] This section provide functions allowing to configure the NVIC interrupts 58 | (IRQ). The Cortex-M0 exceptions are managed by CMSIS functions. 59 | (#) Enable and Configure the priority of the selected IRQ Channels. 60 | The priority can be 0..3. 61 | 62 | -@- Lower priority values gives higher priority. 63 | -@- Priority Order: 64 | (#@) Lowest priority. 65 | (#@) Lowest hardware priority (IRQn position). 66 | 67 | @endverbatim 68 | */ 69 | 70 | /** 71 | * @brief Initializes the NVIC peripheral according to the specified 72 | * parameters in the NVIC_InitStruct. 73 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 74 | * the configuration information for the specified NVIC peripheral. 75 | * @retval None 76 | */ 77 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 78 | { 79 | uint32_t tmppriority = 0x00; 80 | 81 | /* Check the parameters */ 82 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 83 | assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority)); 84 | 85 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 86 | { 87 | /* Compute the Corresponding IRQ Priority --------------------------------*/ 88 | tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02]; 89 | tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8))); 90 | tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)); 91 | 92 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority; 93 | 94 | /* Enable the Selected IRQ Channels --------------------------------------*/ 95 | NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 96 | } 97 | else 98 | { 99 | /* Disable the Selected IRQ Channels -------------------------------------*/ 100 | NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 101 | } 102 | } 103 | 104 | /** 105 | * @brief Selects the condition for the system to enter low power mode. 106 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 107 | * This parameter can be one of the following values: 108 | * @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend. 109 | * @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request. 110 | * @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit. 111 | * @param NewState: new state of LP condition. 112 | * This parameter can be: ENABLE or DISABLE. 113 | * @retval None 114 | */ 115 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 116 | { 117 | /* Check the parameters */ 118 | assert_param(IS_NVIC_LP(LowPowerMode)); 119 | 120 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 121 | 122 | if (NewState != DISABLE) 123 | { 124 | SCB->SCR |= LowPowerMode; 125 | } 126 | else 127 | { 128 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 129 | } 130 | } 131 | 132 | /** 133 | * @brief Configures the SysTick clock source. 134 | * @param SysTick_CLKSource: specifies the SysTick clock source. 135 | * This parameter can be one of the following values: 136 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 137 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 138 | * @retval None 139 | */ 140 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 141 | { 142 | /* Check the parameters */ 143 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 144 | 145 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 146 | { 147 | SysTick->CTRL |= SysTick_CLKSource_HCLK; 148 | } 149 | else 150 | { 151 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 152 | } 153 | } 154 | 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 168 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | #include "debug.h" 21 | #include "delay.h" 22 | #include "main.h" 23 | #include "gui.h" 24 | #include "console.h" 25 | #include "screen.h" 26 | #include 27 | 28 | static uint8_t debug_init_done; 29 | 30 | void debug_init(void) { 31 | debug_init_done = 1; 32 | 33 | debug_put_newline(); 34 | // ##################### 35 | debug("### OpenGround ###\n"); 36 | debug(" (c) by fishpepper \n\n"); 37 | debug("debug: init done\n"); 38 | 39 | debug("debug: "); 40 | if (config_hw_revision == CONFIG_HW_REVISION_EVOLUTION) { 41 | debug("TGY EVOLUTION"); 42 | } else { 43 | debug("FLYSKY/TGY I6S"); 44 | } 45 | debug("\n"); 46 | } 47 | 48 | void debug_putc(uint8_t ch) { 49 | // add \r to newlines 50 | // if (ch == '\n') debug_putc('\r'); 51 | console_putc(ch); 52 | } 53 | 54 | void debug_flush(void) { 55 | if (!debug_init_done) { 56 | return; 57 | } 58 | if (!gui_running()) { 59 | // if gui is not yet active, render console now 60 | if (adc_get_channel_rescaled(CHANNEL_ID_CH3) < 0) { 61 | // show console on switch down 62 | console_render(); 63 | screen_update(); 64 | } else { 65 | lcd_show_logo(); 66 | } 67 | } 68 | } 69 | 70 | 71 | void debug(char *data) { 72 | uint8_t c = (uint8_t)*data++; 73 | while (c) { 74 | debug_putc(c); 75 | c = *data++; 76 | } 77 | } 78 | 79 | 80 | // put hexadecimal number to debug out. 81 | void debug_put_hex8(uint8_t val) { 82 | uint8_t lo = val&0x0F; 83 | uint8_t hi = val>>4; 84 | if (hi < 0x0A) { 85 | hi = '0' + hi; 86 | } else { 87 | hi = 'A' - 0x0A + hi; 88 | } 89 | 90 | if (lo < 0x0A) { 91 | lo = '0' + lo; 92 | } else { 93 | lo = 'A' - 0x0A + lo; 94 | } 95 | debug_putc(hi); 96 | debug_putc(lo); 97 | } 98 | 99 | // put 16bit hexadecimal number to debug out 100 | void debug_put_hex16(uint16_t val) { 101 | debug_put_hex8(val>>8); 102 | debug_put_hex8(val & 0xFF); 103 | } 104 | 105 | // put 32bit hexadecimal number to debug out 106 | void debug_put_hex32(uint32_t val) { 107 | debug_put_hex8(val>>24); 108 | debug_put_hex8(val>>16); 109 | debug_put_hex8(val>> 8); 110 | debug_put_hex8(val & 0xFF); 111 | } 112 | 113 | // output a signed 8-bit number to uart 114 | void debug_put_int8(int8_t c) { 115 | uint8_t tmp; 116 | uint8_t mul; 117 | uint8_t l; 118 | uint8_t uint_s; 119 | 120 | if (c < 0) { 121 | debug_putc('-'); 122 | uint_s = -c; 123 | } else { 124 | uint_s = c; 125 | } 126 | 127 | l = 0; 128 | for (mul = 100; mul > 0; mul = mul/ 10) { 129 | tmp = '0'; 130 | while (uint_s >= mul) { 131 | uint_s -= mul; 132 | tmp++; 133 | l = 1; 134 | } 135 | if ((l == 0) && (tmp == '0') && (mul != 1)) { 136 | // dont print spacer 137 | // debug_putc(' '); 138 | } else { 139 | debug_putc(tmp); 140 | } 141 | } 142 | } 143 | 144 | // output an unsigned 8-bit number to uart 145 | void debug_put_uint8(uint8_t c) { 146 | uint8_t tmp; 147 | uint8_t mul; 148 | uint8_t l; 149 | 150 | l = 0; 151 | for (mul = 100; mul >0 ; mul = mul/ 10) { 152 | tmp = '0'; 153 | while (c >= mul) { 154 | c -= mul; 155 | tmp++; 156 | l = 1; 157 | } 158 | if ((l == 0) && (tmp == '0') && (mul != 1)) { 159 | // dont print spacer 160 | // debug_putc(' '); 161 | } else { 162 | debug_putc(tmp); 163 | } 164 | } 165 | } 166 | 167 | // output an unsigned 16-bit number to uart 168 | void debug_put_uint16(uint16_t c) { 169 | uint8_t tmp; 170 | uint8_t l = 0; 171 | // loop unrolling is better(no int16 arithmetic) 172 | /*for (mul = 10000; mul>0; mul = mul/ 10) { 173 | uint16_t mul; 174 | 175 | l = 0; 176 | tmp = '0'; 177 | while (c>=mul) { 178 | c -= mul; 179 | tmp++; 180 | l = 1; 181 | } 182 | if ((l == 0) && (tmp == '0') && (mul!=1)) { 183 | // debug_putc(' '); 184 | } else { 185 | debug_putc(tmp); 186 | } 187 | }*/ 188 | tmp = 0; 189 | while (c >= 10000L) { 190 | c -= 10000L; 191 | tmp++; 192 | l = 1; 193 | } 194 | if (tmp != 0) debug_putc('0' + tmp); 195 | 196 | tmp = 0; 197 | while (c >= 1000L) { 198 | c -= 1000L; 199 | tmp++; 200 | l = 1; 201 | } 202 | if (l || (tmp != 0)) debug_putc('0' + tmp); 203 | 204 | tmp = 0; 205 | while (c >= 100) { 206 | c -= 100; 207 | tmp++; 208 | l = 1; 209 | } 210 | if (l || (tmp != 0)) debug_putc('0' + tmp); 211 | 212 | tmp = 0; 213 | while (c >= 10) { 214 | c -= 10; 215 | tmp++; 216 | l = 1; 217 | } 218 | if (l || (tmp != 0)) debug_putc('0' + tmp); 219 | 220 | debug_putc('0' + (uint8_t)c); 221 | } 222 | 223 | void debug_put_fixed2(uint16_t c) { 224 | uint8_t tmp; 225 | uint8_t l = 0; 226 | tmp = 0; 227 | while (c >= 10000L) { 228 | c -= 10000L; 229 | tmp++; 230 | l = 1; 231 | } 232 | if (tmp != 0) debug_putc('0' + tmp); 233 | 234 | tmp = 0; 235 | while (c >= 1000L) { 236 | c -= 1000L; 237 | tmp++; 238 | l = 1; 239 | } 240 | if (l || (tmp != 0)) debug_putc('0' + tmp); 241 | 242 | tmp = 0; 243 | while (c >= 100) { 244 | c -= 100; 245 | tmp++; 246 | l = 1; 247 | } 248 | if (l || (tmp != 0)) debug_putc('0' + tmp); 249 | 250 | debug_putc('.'); 251 | 252 | tmp = 0; 253 | while (c >= 10) { 254 | c -= 10; 255 | tmp++; 256 | l = 1; 257 | } 258 | if (l || (tmp != 0)) debug_putc('0' + tmp); 259 | 260 | debug_putc('0' + (uint8_t)c); 261 | } 262 | 263 | void debug_put_newline(void) { 264 | debug_putc('\n'); 265 | } 266 | 267 | uint32_t debug_is_initialized(void) { 268 | return debug_init_done; 269 | } 270 | -------------------------------------------------------------------------------- /src/lcd.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 fishpepper gmail.com 3 | 4 | This program is free software: you can redistribute it and/ or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | 17 | author: fishpepper gmail.com 18 | */ 19 | 20 | // see: 21 | // http://fishpepper.de/2016/09/15/openground-part-1-components-pinout/ 22 | // http://pdf.masters.com.pl/SITRONIX/ST7567.PDF 23 | // http://edeca.net/wp/electronics/the-st7565-display-controller/ 24 | // https://github.com/opentx/opentx/blob/ 25 | // dbd8abbfe8343b5d7f542304d47e232140307b95/radio/src/targets/stock/lcd_driver.cpp 26 | 27 | #include "lcd.h" 28 | #include "wdt.h" 29 | #include "delay.h" 30 | #include "logo.h" 31 | #include 32 | #include 33 | #include 34 | 35 | // INTERNAL FUNCTIONS 36 | static void lcd_init_gpio(void); 37 | static void lcd_init_rcc(void); 38 | static void lcd_reset(void); 39 | static void lcd_write_command(uint8_t data); 40 | 41 | 42 | void lcd_init(void) { 43 | lcd_init_rcc(); 44 | lcd_init_gpio(); 45 | lcd_reset(); 46 | } 47 | 48 | static void lcd_init_rcc(void) { 49 | // enable all peripheral clocks: 50 | rcc_periph_clock_enable(GPIO_RCC(LCD_DATA_GPIO)); 51 | rcc_periph_clock_enable(GPIO_RCC(LCD_RW_GPIO)); 52 | rcc_periph_clock_enable(GPIO_RCC(LCD_RST_GPIO)); 53 | rcc_periph_clock_enable(GPIO_RCC(LCD_RS_GPIO)); 54 | rcc_periph_clock_enable(GPIO_RCC(LCD_RD_GPIO)); 55 | rcc_periph_clock_enable(GPIO_RCC(LCD_CS_GPIO)); 56 | } 57 | 58 | static void lcd_init_gpio(void) { 59 | // set all gpio directions to output 60 | // set powerdown trigger pin as output 61 | // data lines D0..D7 62 | gpio_mode_setup(LCD_DATA_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, 0xFF); 63 | gpio_set_output_options(LCD_DATA_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, 0xFF); 64 | 65 | // rw 66 | gpio_mode_setup(LCD_RW_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_RW_PIN); 67 | gpio_set_output_options(LCD_RW_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LCD_RW_PIN); 68 | // rst 69 | gpio_mode_setup(LCD_RST_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_RST_PIN); 70 | gpio_set_output_options(LCD_RST_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LCD_RST_PIN); 71 | // rs 72 | gpio_mode_setup(LCD_RS_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_RS_PIN); 73 | gpio_set_output_options(LCD_RS_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LCD_RS_PIN); 74 | // rd 75 | gpio_mode_setup(LCD_RD_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_RD_PIN); 76 | gpio_set_output_options(LCD_RD_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LCD_RD_PIN); 77 | // cs 78 | gpio_mode_setup(LCD_CS_GPIO, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LCD_CS_PIN); 79 | gpio_set_output_options(LCD_CS_GPIO, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, LCD_CS_PIN); 80 | 81 | // set default pin levels: 82 | LCD_RST_LO(); 83 | LCD_CS_HI(); 84 | LCD_RW_LO(); 85 | LCD_RD_HI(); 86 | LCD_RS_HI(); 87 | } 88 | 89 | static void lcd_write_command(uint8_t data) { 90 | // make sure write is high(disabled) 91 | LCD_CS_LO(); 92 | // command mode 93 | LCD_RS_LO(); 94 | // 95 | LCD_RW_LO(); 96 | 97 | // write data to port d0...d7 98 | LCD_DATA_SET(data); 99 | 100 | // execute write 101 | LCD_RD_HI(); 102 | LCD_RD_LO(); 103 | LCD_RS_HI(); 104 | 105 | // deselect device 106 | LCD_CS_HI(); 107 | } 108 | 109 | 110 | void lcd_powerdown(void) { 111 | // switch display off 112 | lcd_write_command(LCD_CMD_DISPLAY_OFF); 113 | 114 | // all pixels on 115 | lcd_write_command(LCD_CMD_MODE_ALLBLACK); 116 | 117 | // wait 118 | wdt_reset(); 119 | delay_ms(100); 120 | wdt_reset(); 121 | delay_ms(100); 122 | wdt_reset(); 123 | delay_ms(100); 124 | } 125 | 126 | static void lcd_reset(void) { 127 | // wait for voltages to be stable 128 | delay_ms(100); 129 | 130 | // trigger hw reset 131 | LCD_RST_LO(); 132 | delay_us(10); // at least 5us 133 | LCD_RST_HI(); 134 | delay_us(1500); // at least 5us? 135 | 136 | // send software reset command 137 | lcd_write_command(LCD_CMD_RESET); 138 | 139 | // switch display off 140 | lcd_write_command(LCD_CMD_DISPLAY_OFF); 141 | 142 | // do not set all pixels to black(..._ALLBLACK) 143 | lcd_write_command(LCD_CMD_MODE_RAM); 144 | 145 | // set to 1/ 7 bias: 146 | lcd_write_command(LCD_CMD_BIAS_1_7); // opentx uses LCD_CMD_BIAS_1_9 147 | 148 | // set seg and com directions 149 | lcd_write_command(LCD_CMD_COM_NORMAL); // INVERSE); 150 | // normal or inverted? 151 | lcd_write_command(LCD_CMD_SEG_INVERSE); // NORMAL); 152 | 153 | // power control -> all boosters on 154 | lcd_write_command(LCD_CMD_POWERCTRL_ALL_ON); 155 | 156 | // regulator ratio 157 | lcd_write_command(LCD_CMD_REG_RATIO_011); // opentx uses LCD_CMD_REG_RATIO_101 ? 158 | 159 | // set EV(contrast?), this is 2byte command 160 | lcd_write_command(LCD_CMD_EV); 161 | lcd_write_command(40); // dynamic contrast 0...63 162 | 163 | // set startline to 0 164 | lcd_write_command(LCD_CMD_SET_STARTLINE + 0); 165 | // set start page to 0 166 | lcd_write_command(LCD_CMD_SET_PAGESTART + 0); 167 | 168 | // set col address of ram to 0 169 | lcd_write_command(LCD_CMD_SET_COL_LO + 0); 170 | lcd_write_command(LCD_CMD_SET_COL_HI + 0); 171 | 172 | // switch display on 173 | lcd_write_command(LCD_CMD_DISPLAY_ON); 174 | } 175 | 176 | void lcd_send_data(const uint8_t *buf) { 177 | uint32_t x, y; 178 | 179 | // set start to 0,0 180 | lcd_write_command(LCD_CMD_SET_STARTLINE + 0); 181 | lcd_write_command(LCD_CMD_SET_PAGESTART + 2); 182 | 183 | // set col address of ram to 0 184 | lcd_write_command(LCD_CMD_SET_COL_LO + 0); 185 | lcd_write_command(LCD_CMD_SET_COL_HI + 0); 186 | 187 | for (y = 0; y < 8; y++) { 188 | // start on col 0 189 | lcd_write_command(LCD_CMD_SET_COL_LO + 0); 190 | lcd_write_command(LCD_CMD_SET_COL_HI + 0); 191 | // page start 192 | lcd_write_command(LCD_CMD_SET_PAGESTART + y); 193 | 194 | LCD_CS_LO(); 195 | LCD_RS_HI(); 196 | LCD_RW_LO(); 197 | 198 | // send 4 dummy bytes(132-128) 199 | for (x = 4; x > 0; --x) { 200 | LCD_DATA_SET(0x00); 201 | LCD_RD_HI(); 202 | LCD_RD_LO(); 203 | } 204 | 205 | for (x = 128; x > 0; --x) { 206 | LCD_DATA_SET(*buf++); 207 | // execute write 208 | LCD_RD_HI(); 209 | LCD_RD_LO(); 210 | } 211 | } 212 | 213 | LCD_RD_HI(); 214 | 215 | // deselect device 216 | LCD_CS_HI(); 217 | LCD_RW_HI(); 218 | } 219 | 220 | void lcd_show_logo(void) { 221 | lcd_send_data(logo_data); 222 | } 223 | -------------------------------------------------------------------------------- /src/fonts/metric15x26.h: -------------------------------------------------------------------------------- 1 | /* 2 | Based on the "Metric" font from https://saelaenx.wordpress.com 3 | Converted for GLCD format by Christian Isenberg 27/09/2015 4 | Modified for OpenGround by fishpepper 2016 5 | */ 6 | 7 | #ifndef __FONT_METRIC15x26_H__ 8 | #define __FONT_METRIC15x26_H__ 9 | 10 | #include 11 | 12 | // font data 13 | const uint8_t font_metric15x26[] = { 14 | 0x00, 0x00, // size of zero indicates fixed width font 15 | 15, // width 16 | 26, // height 17 | '*', // first char 18 | 19, // char count 19 | 20 | //* 21 | 0x3e, 0x7f, 0x63, 0x63, 0x63, 0x7f, 0x3e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 22 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 23 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 24 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 25 | //+ 26 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0xc0, 0xc0, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 27 | 0x0, 0x78, 0x78, 0x78, 0x78, 0x78, 0xff, 0xff, 0xff, 0xff, 0x78, 0x78, 0x78, 0x78, 0x78, 28 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 29 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 30 | //, 31 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 32 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 33 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 34 | 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 35 | //- 36 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 37 | 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 38 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 39 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 40 | //. 41 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 42 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 43 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 44 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 45 | // 46 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 47 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 48 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 49 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 50 | //0 51 | 0xfc, 0xfe, 0xff, 0xff, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0xff, 0xff, 0xfe, 0xfc, 52 | 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 53 | 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 54 | 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 55 | //1 56 | 0x0, 0x0, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0x0, 0x0, 0x0, 0x0, 57 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 58 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 59 | 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 60 | //2 61 | 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 62 | 0xe0, 0xf0, 0xf8, 0xf8, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x7f, 0x7f, 0x3f, 0x1f, 63 | 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 64 | 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 65 | //3 66 | 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 67 | 0x0, 0x0, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xff, 0xff, 0xff, 0xff, 68 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 69 | 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 70 | //4 71 | 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 72 | 0x1f, 0x3f, 0x7f, 0x7f, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xff, 0xff, 0xff, 0xff, 73 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 74 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x3, 75 | //5 76 | 0xfc, 0xfe, 0xff, 0xff, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 77 | 0x1f, 0x3f, 0x7f, 0x7f, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xf8, 0xf8, 0xf0, 0xe0, 78 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 79 | 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 80 | //6 81 | 0xfc, 0xfe, 0xff, 0xff, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x0, 0x0, 82 | 0xff, 0xff, 0xff, 0xff, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xf8, 0xf8, 0xf0, 0xe0, 83 | 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 84 | 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 85 | //7 86 | 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 87 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 88 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 89 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x3, 90 | //8 91 | 0xfc, 0xfe, 0xff, 0xff, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 92 | 0xff, 0xff, 0xff, 0xff, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xff, 0xff, 0xff, 0xff, 93 | 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 94 | 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 95 | //9 96 | 0xfc, 0xfe, 0xff, 0xff, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xff, 0xff, 0xfe, 0xfc, 97 | 0x1f, 0x3f, 0x7f, 0x7f, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0xff, 0xff, 0xff, 0xff, 98 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 99 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x3, 100 | //: 101 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 102 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 103 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 104 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 105 | //; 106 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 107 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 108 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 109 | 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 110 | /* w 111 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 112 | 0xf8, 0xf8, 0xf8, 0xf8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8, 0xf8, 0xf8, 0xf8, 113 | 0xff, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xc0, 0xf0, 0xc0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 114 | 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 0x1, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0*/ 115 | 116 | }; 117 | #endif // __FONT_METRIC15x26_H__ 118 | 119 | --------------------------------------------------------------------------------