├── .gitignore ├── Arduino.h ├── AudioStream.cpp ├── AudioStream.h ├── Bounce.cpp ├── Bounce.h ├── Client.h ├── DMAChannel.cpp ├── DMAChannel.h ├── Encoder.cpp ├── Encoder.h ├── HardwareSerial.h ├── HardwareSerial1.cpp ├── HardwareSerial2.cpp ├── HardwareSerial3.cpp ├── IPAddress.cpp ├── IPAddress.h ├── IntervalTimer.cpp ├── IntervalTimer.h ├── Makefile ├── Print.cpp ├── Print.h ├── Printable.h ├── README.md ├── SPIFIFO.h ├── SeeedOLED.cpp ├── SeeedOLED.h ├── Server.h ├── Stream.cpp ├── Stream.h ├── Tone.cpp ├── Udp.h ├── WCharacter.h ├── WConstants.h ├── WMath.cpp ├── WProgram.h ├── WString.cpp ├── WString.h ├── analog.c ├── analog_oscillator.cc ├── analog_oscillator.h ├── arm_common_tables.h ├── arm_math.h ├── avr ├── eeprom.h ├── interrupt.h ├── io.h ├── pgmspace.h ├── power.h ├── sleep.h └── wdt.h ├── avr_emulation.cpp ├── avr_emulation.h ├── avr_functions.h ├── binary.h ├── core_cm4.h ├── core_cm4_simd.h ├── core_cmInstr.h ├── core_id.h ├── core_pins.h ├── digital_oscillator.cc ├── digital_oscillator.h ├── eeprom.c ├── elapsedMillis.h ├── envelope.h ├── i2c_t3.cpp ├── i2c_t3.h ├── keylayouts.c ├── keylayouts.h ├── kinetis.h ├── macro_oscillator.cc ├── macro_oscillator.h ├── main.cpp ├── main.js ├── make ├── math_helper.c ├── math_helper.h ├── memcpy-armv7m.S ├── mk20dx128.c ├── mk20dx128.h ├── mk20dx128.ld ├── mk20dx256.ld ├── mk66fx1m0.ld ├── mkl26z64.ld ├── my_environment_back.sh ├── new.cpp ├── new.h ├── nonstd.c ├── npm-debug.log ├── out.txt ├── parameter_interpolation.h ├── pins_arduino.h ├── pins_teensy.c ├── random.cc ├── resources.cc ├── resources.h ├── ser_print.c ├── ser_print.h ├── serial1.c ├── serial1_doughboy.txt ├── serial2.c ├── serial3.c ├── settings.cc ├── settings.h ├── signature_waveshaper.h ├── stmlib ├── .gitignore ├── LICENSE ├── README.md ├── algorithms │ ├── note_stack.h │ ├── pattern_predictor.h │ ├── tiny_map.h │ └── voice_allocator.h ├── fft │ └── shy_fft.h ├── linker_scripts │ ├── stm32f10x_flash_cl.ld │ ├── stm32f10x_flash_cl_application.ld │ ├── stm32f10x_flash_cl_application_small.ld │ ├── stm32f10x_flash_hd.ld │ ├── stm32f10x_flash_hd_application.ld │ ├── stm32f10x_flash_hd_application_small.ld │ ├── stm32f10x_flash_md.ld │ ├── stm32f10x_flash_md_application.ld │ ├── stm32f10x_flash_md_application_small.ld │ └── stm32f4xx_flash.ld ├── makefile.inc ├── midi │ └── midi.h ├── programming │ ├── jtag │ │ ├── erase_f10x.cfg │ │ ├── erase_f4xx.cfg │ │ ├── interface.cfg │ │ ├── postlude.cfg │ │ ├── prelude_f10x.cfg │ │ ├── prelude_f4xx.cfg │ │ ├── stm32f10x.cfg │ │ └── stm32f4xx.cfg │ ├── merge_hex.awk │ └── serial │ │ └── stm32loader.py ├── stmlib.h ├── system │ ├── bootloader_utils.cc │ ├── bootloader_utils.h │ ├── flash_programming.h │ ├── storage.h │ ├── system_clock.cc │ ├── system_clock.h │ └── uid.h ├── third_party │ └── STM │ │ ├── CMSIS │ │ ├── CM3_f10x │ │ │ ├── core_cm3.c │ │ │ ├── core_cm3.h │ │ │ ├── startup │ │ │ │ ├── arm │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ └── startup_stm32f10x_md.s │ │ │ │ ├── gcc │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ └── startup_stm32f10x_md.s │ │ │ │ └── iar │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ └── startup_stm32f10x_md.s │ │ │ ├── stm32f10x.h │ │ │ ├── system_stm32f10x.c │ │ │ └── system_stm32f10x.h │ │ └── CM3_f4xx │ │ │ ├── arm_common_tables.h │ │ │ ├── arm_math.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm3.c │ │ │ ├── core_cm3.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm4_simd.h │ │ │ ├── core_cmFunc.h │ │ │ ├── core_cmInstr.h │ │ │ ├── startup │ │ │ ├── arm │ │ │ │ └── startup_stm32f4xx.s │ │ │ ├── gcc │ │ │ │ └── startup_stm32f4xx.s │ │ │ └── iar │ │ │ │ └── startup_stm32f4xx.s │ │ │ ├── stm32f4xx.h │ │ │ ├── system_stm32f4xx.c │ │ │ └── system_stm32f4xx.h │ │ ├── STM32F10x_StdPeriph_Driver │ │ ├── inc │ │ │ ├── misc.h │ │ │ ├── stm32f10x_adc.h │ │ │ ├── stm32f10x_bkp.h │ │ │ ├── stm32f10x_can.h │ │ │ ├── stm32f10x_crc.h │ │ │ ├── stm32f10x_dac.h │ │ │ ├── stm32f10x_dbgmcu.h │ │ │ ├── stm32f10x_dma.h │ │ │ ├── stm32f10x_exti.h │ │ │ ├── stm32f10x_flash.h │ │ │ ├── stm32f10x_fsmc.h │ │ │ ├── stm32f10x_gpio.h │ │ │ ├── stm32f10x_i2c.h │ │ │ ├── stm32f10x_iwdg.h │ │ │ ├── stm32f10x_pwr.h │ │ │ ├── stm32f10x_rcc.h │ │ │ ├── stm32f10x_rtc.h │ │ │ ├── stm32f10x_sdio.h │ │ │ ├── stm32f10x_spi.h │ │ │ ├── stm32f10x_tim.h │ │ │ ├── stm32f10x_usart.h │ │ │ └── stm32f10x_wwdg.h │ │ └── src │ │ │ ├── misc.c │ │ │ ├── stm32f10x_adc.c │ │ │ ├── stm32f10x_bkp.c │ │ │ ├── stm32f10x_can.c │ │ │ ├── stm32f10x_crc.c │ │ │ ├── stm32f10x_dac.c │ │ │ ├── stm32f10x_dbgmcu.c │ │ │ ├── stm32f10x_dma.c │ │ │ ├── stm32f10x_exti.c │ │ │ ├── stm32f10x_flash.c │ │ │ ├── stm32f10x_fsmc.c │ │ │ ├── stm32f10x_gpio.c │ │ │ ├── stm32f10x_i2c.c │ │ │ ├── stm32f10x_iwdg.c │ │ │ ├── stm32f10x_pwr.c │ │ │ ├── stm32f10x_rcc.c │ │ │ ├── stm32f10x_rtc.c │ │ │ ├── stm32f10x_sdio.c │ │ │ ├── stm32f10x_spi.c │ │ │ ├── stm32f10x_tim.c │ │ │ ├── stm32f10x_usart.c │ │ │ └── stm32f10x_wwdg.c │ │ ├── STM32F4xx_StdPeriph_Driver │ │ ├── inc │ │ │ ├── misc.h │ │ │ ├── stm32f4xx_adc.h │ │ │ ├── stm32f4xx_can.h │ │ │ ├── stm32f4xx_crc.h │ │ │ ├── stm32f4xx_cryp.h │ │ │ ├── stm32f4xx_dac.h │ │ │ ├── stm32f4xx_dbgmcu.h │ │ │ ├── stm32f4xx_dcmi.h │ │ │ ├── stm32f4xx_dma.h │ │ │ ├── stm32f4xx_exti.h │ │ │ ├── stm32f4xx_flash.h │ │ │ ├── stm32f4xx_fsmc.h │ │ │ ├── stm32f4xx_gpio.h │ │ │ ├── stm32f4xx_hash.h │ │ │ ├── stm32f4xx_i2c.h │ │ │ ├── stm32f4xx_iwdg.h │ │ │ ├── stm32f4xx_pwr.h │ │ │ ├── stm32f4xx_rcc.h │ │ │ ├── stm32f4xx_rng.h │ │ │ ├── stm32f4xx_rtc.h │ │ │ ├── stm32f4xx_sdio.h │ │ │ ├── stm32f4xx_spi.h │ │ │ ├── stm32f4xx_syscfg.h │ │ │ ├── stm32f4xx_tim.h │ │ │ ├── stm32f4xx_usart.h │ │ │ └── stm32f4xx_wwdg.h │ │ └── src │ │ │ ├── misc.c │ │ │ ├── stm32f4xx_adc.c │ │ │ ├── stm32f4xx_can.c │ │ │ ├── stm32f4xx_crc.c │ │ │ ├── stm32f4xx_cryp.c │ │ │ ├── stm32f4xx_cryp_aes.c │ │ │ ├── stm32f4xx_cryp_des.c │ │ │ ├── stm32f4xx_cryp_tdes.c │ │ │ ├── stm32f4xx_dac.c │ │ │ ├── stm32f4xx_dbgmcu.c │ │ │ ├── stm32f4xx_dcmi.c │ │ │ ├── stm32f4xx_dma.c │ │ │ ├── stm32f4xx_exti.c │ │ │ ├── stm32f4xx_flash.c │ │ │ ├── stm32f4xx_fsmc.c │ │ │ ├── stm32f4xx_gpio.c │ │ │ ├── stm32f4xx_hash.c │ │ │ ├── stm32f4xx_hash_md5.c │ │ │ ├── stm32f4xx_hash_sha1.c │ │ │ ├── stm32f4xx_i2c.c │ │ │ ├── stm32f4xx_iwdg.c │ │ │ ├── stm32f4xx_pwr.c │ │ │ ├── stm32f4xx_rcc.c │ │ │ ├── stm32f4xx_rng.c │ │ │ ├── stm32f4xx_rtc.c │ │ │ ├── stm32f4xx_sdio.c │ │ │ ├── stm32f4xx_spi.c │ │ │ ├── stm32f4xx_syscfg.c │ │ │ ├── stm32f4xx_tim.c │ │ │ ├── stm32f4xx_usart.c │ │ │ └── stm32f4xx_wwdg.c │ │ ├── STM32_USB-FS-Device_Driver │ │ ├── inc │ │ │ ├── otgd_fs_cal.h │ │ │ ├── otgd_fs_dev.h │ │ │ ├── otgd_fs_int.h │ │ │ ├── otgd_fs_pcd.h │ │ │ ├── otgd_fs_regs.h │ │ │ ├── usb_core.h │ │ │ ├── usb_def.h │ │ │ ├── usb_init.h │ │ │ ├── usb_int.h │ │ │ ├── usb_lib.h │ │ │ ├── usb_mem.h │ │ │ ├── usb_regs.h │ │ │ ├── usb_sil.h │ │ │ └── usb_type.h │ │ └── src │ │ │ ├── otgd_fs_cal.c │ │ │ ├── otgd_fs_dev.c │ │ │ ├── otgd_fs_int.c │ │ │ ├── otgd_fs_pcd.c │ │ │ ├── usb_core.c │ │ │ ├── usb_init.c │ │ │ ├── usb_int.c │ │ │ ├── usb_mem.c │ │ │ ├── usb_regs.c │ │ │ └── usb_sil.c │ │ ├── stm32f10x_conf.h │ │ ├── stm32f4xx_conf.h │ │ └── usb_conf.h ├── tools │ ├── __init__.py │ └── resources_compiler.py ├── ui │ └── event_queue.h └── utils │ ├── crc32.h │ ├── dsp.h │ ├── murmurhash3.h │ ├── random.cc │ ├── random.h │ ├── ring_buffer.h │ └── stream_buffer.h ├── touch.c ├── ui.h ├── usb_desc.c ├── usb_desc.h ├── usb_dev.c ├── usb_dev.h ├── usb_flightsim.cpp ├── usb_flightsim.h ├── usb_inst.cpp ├── usb_joystick.c ├── usb_joystick.h ├── usb_keyboard.c ├── usb_keyboard.h ├── usb_mem.c ├── usb_mem.h ├── usb_midi.c ├── usb_midi.h ├── usb_mouse.c ├── usb_mouse.h ├── usb_mtp.c ├── usb_mtp.h ├── usb_names.h ├── usb_rawhid.c ├── usb_rawhid.h ├── usb_seremu.c ├── usb_seremu.h ├── usb_serial.c ├── usb_serial.h ├── usb_undef.h ├── util ├── atomic.h ├── crc16.h ├── delay.h └── parity.h ├── utility ├── direct_pin_read.h ├── interrupt_config.h └── interrupt_pins.h ├── vco_jitter_source.h ├── wiring.h ├── wiring_private.h ├── yield.c └── yield.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.d 2 | *.o 3 | *.elf 4 | *.hex 5 | -------------------------------------------------------------------------------- /Arduino.h: -------------------------------------------------------------------------------- 1 | #include "WProgram.h" 2 | #include "pins_arduino.h" 3 | -------------------------------------------------------------------------------- /Bounce.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Please read Bounce.h for information about the liscence and authors 3 | 4 | #include "WProgram.h" 5 | #include "Bounce.h" 6 | 7 | 8 | Bounce::Bounce(uint8_t pin,unsigned long interval_millis) 9 | { 10 | interval(interval_millis); 11 | previous_millis = millis(); 12 | state = digitalRead(pin); 13 | this->pin = pin; 14 | } 15 | 16 | 17 | void Bounce::write(int new_state) 18 | { 19 | this->state = new_state; 20 | digitalWrite(pin,state); 21 | } 22 | 23 | 24 | void Bounce::interval(unsigned long interval_millis) 25 | { 26 | this->interval_millis = interval_millis; 27 | this->rebounce_millis = 0; 28 | } 29 | 30 | void Bounce::rebounce(unsigned long interval) 31 | { 32 | this->rebounce_millis = interval; 33 | } 34 | 35 | 36 | 37 | int Bounce::update() 38 | { 39 | if ( debounce() ) { 40 | rebounce(0); 41 | return stateChanged = 1; 42 | } 43 | 44 | // We need to rebounce, so simulate a state change 45 | 46 | if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) { 47 | previous_millis = millis(); 48 | rebounce(0); 49 | return stateChanged = 1; 50 | } 51 | 52 | return stateChanged = 0; 53 | } 54 | 55 | 56 | unsigned long Bounce::duration() 57 | { 58 | return millis() - previous_millis; 59 | } 60 | 61 | 62 | int Bounce::read() 63 | { 64 | return (int)state; 65 | } 66 | 67 | 68 | // Protected: debounces the pin 69 | int Bounce::debounce() { 70 | 71 | uint8_t newState = digitalRead(pin); 72 | if (state != newState ) { 73 | if (millis() - previous_millis >= interval_millis) { 74 | previous_millis = millis(); 75 | state = newState; 76 | return 1; 77 | } 78 | } 79 | 80 | return 0; 81 | 82 | } 83 | 84 | // The risingEdge method is true for one scan after the de-bounced input goes from off-to-on. 85 | bool Bounce::risingEdge() { return stateChanged && state; } 86 | // The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off. 87 | bool Bounce::fallingEdge() { return stateChanged && !state; } 88 | 89 | -------------------------------------------------------------------------------- /Bounce.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 | * MA 02110-1301, USA. 17 | */ 18 | 19 | 20 | 21 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 22 | Main code by Thomas O Fredericks 23 | Rebounce and duration functions contributed by Eric Lowry 24 | Write function contributed by Jim Schimpf 25 | risingEdge and fallingEdge contributed by Tom Harkaway 26 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 27 | 28 | #ifndef Bounce_h 29 | #define Bounce_h 30 | 31 | #include 32 | 33 | class Bounce 34 | { 35 | 36 | public: 37 | // Initialize 38 | Bounce(uint8_t pin, unsigned long interval_millis ); 39 | // Sets the debounce interval 40 | void interval(unsigned long interval_millis); 41 | // Updates the pin 42 | // Returns 1 if the state changed 43 | // Returns 0 if the state did not change 44 | int update(); 45 | // Forces the pin to signal a change (through update()) in X milliseconds 46 | // even if the state does not actually change 47 | // Example: press and hold a button and have it repeat every X milliseconds 48 | void rebounce(unsigned long interval); 49 | // Returns the updated pin state 50 | int read(); 51 | // Sets the stored pin state 52 | void write(int new_state); 53 | // Returns the number of milliseconds the pin has been in the current state 54 | unsigned long duration(); 55 | // The risingEdge method is true for one scan after the de-bounced input goes from off-to-on. 56 | bool risingEdge(); 57 | // The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off. 58 | bool fallingEdge(); 59 | 60 | protected: 61 | int debounce(); 62 | unsigned long previous_millis, interval_millis, rebounce_millis; 63 | uint8_t state; 64 | uint8_t pin; 65 | uint8_t stateChanged; 66 | }; 67 | 68 | #endif 69 | 70 | 71 | -------------------------------------------------------------------------------- /Client.h: -------------------------------------------------------------------------------- 1 | #if ARDUINO >= 100 2 | 3 | #ifndef client_h 4 | #define client_h 5 | #include "Print.h" 6 | #include "Stream.h" 7 | #include "IPAddress.h" 8 | 9 | class Client : public Stream { 10 | 11 | public: 12 | virtual int connect(IPAddress ip, uint16_t port) =0; 13 | virtual int connect(const char *host, uint16_t port) =0; 14 | virtual size_t write(uint8_t) =0; 15 | virtual size_t write(const uint8_t *buf, size_t size) =0; 16 | virtual int available() = 0; 17 | virtual int read() = 0; 18 | virtual int read(uint8_t *buf, size_t size) = 0; 19 | virtual int peek() = 0; 20 | virtual void flush() = 0; 21 | virtual void stop() = 0; 22 | virtual uint8_t connected() = 0; 23 | virtual operator bool() = 0; 24 | protected: 25 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 26 | }; 27 | 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /Encoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Encoder.h" 3 | 4 | // Yes, all the code is in the header file, to provide the user 5 | // configure options with #define (before they include it), and 6 | // to facilitate some crafty optimizations! 7 | 8 | Encoder_internal_state_t * Encoder::interruptArgs[]; 9 | 10 | 11 | -------------------------------------------------------------------------------- /HardwareSerial1.cpp: -------------------------------------------------------------------------------- 1 | #include "HardwareSerial.h" 2 | 3 | HardwareSerial Serial1; 4 | 5 | void serialEvent1() __attribute__((weak)); 6 | void serialEvent1() {} 7 | -------------------------------------------------------------------------------- /HardwareSerial2.cpp: -------------------------------------------------------------------------------- 1 | #include "HardwareSerial.h" 2 | 3 | HardwareSerial2 Serial2; 4 | 5 | void serialEvent2() __attribute__((weak)); 6 | void serialEvent2() {} 7 | -------------------------------------------------------------------------------- /HardwareSerial3.cpp: -------------------------------------------------------------------------------- 1 | #include "HardwareSerial.h" 2 | 3 | HardwareSerial3 Serial3; 4 | 5 | void serialEvent3() __attribute__((weak)); 6 | void serialEvent3() {} 7 | -------------------------------------------------------------------------------- /IPAddress.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "IPAddress.h" 3 | 4 | size_t IPAddress::printTo(Print& p) const 5 | { 6 | int i=0; 7 | while (1) { 8 | p.print(_address.bytes[i], DEC); 9 | if (++i >= 4) return 4; 10 | p.write('.'); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /IntervalTimer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Daniel Gilbert, loglow@gmail.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in the 5 | Software without restriction, including without limitation the rights to use, copy, 6 | modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 7 | and to permit persons to whom the Software is furnished to do so, subject to the 8 | following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 19 | 20 | 21 | #ifndef __INTERVALTIMER_H__ 22 | #define __INTERVALTIMER_H__ 23 | 24 | #include "kinetis.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | class IntervalTimer { 31 | private: 32 | typedef void (*ISR)(); 33 | typedef volatile uint32_t* reg; 34 | enum {TIMER_OFF, TIMER_PIT}; 35 | #if defined(KINETISK) 36 | static const uint8_t NUM_PIT = 4; 37 | #elif defined(KINETISL) 38 | static const uint8_t NUM_PIT = 2; 39 | #endif 40 | static const uint32_t MAX_PERIOD = UINT32_MAX / (F_BUS / 1000000.0); 41 | static void enable_PIT(); 42 | static void disable_PIT(); 43 | static bool PIT_enabled; 44 | static bool PIT_used[NUM_PIT]; 45 | static ISR PIT_ISR[NUM_PIT]; 46 | bool allocate_PIT(uint32_t newValue); 47 | void start_PIT(uint32_t newValue); 48 | void stop_PIT(); 49 | bool status; 50 | uint8_t PIT_id; 51 | reg PIT_LDVAL; 52 | reg PIT_TCTRL; 53 | uint8_t IRQ_PIT_CH; 54 | uint8_t nvic_priority; 55 | ISR myISR; 56 | bool beginCycles(ISR newISR, uint32_t cycles); 57 | public: 58 | IntervalTimer() { status = TIMER_OFF; nvic_priority = 128; } 59 | ~IntervalTimer() { end(); } 60 | bool begin(ISR newISR, unsigned int newPeriod) { 61 | if (newPeriod == 0 || newPeriod > MAX_PERIOD) return false; 62 | uint32_t newValue = (F_BUS / 1000000) * newPeriod - 1; 63 | return beginCycles(newISR, newValue); 64 | } 65 | bool begin(ISR newISR, int newPeriod) { 66 | if (newPeriod < 0) return false; 67 | return begin(newISR, (unsigned int)newPeriod); 68 | } 69 | bool begin(ISR newISR, unsigned long newPeriod) { 70 | return begin(newISR, (unsigned int)newPeriod); 71 | } 72 | bool begin(ISR newISR, long newPeriod) { 73 | return begin(newISR, (int)newPeriod); 74 | } 75 | bool begin(ISR newISR, float newPeriod) { 76 | if (newPeriod <= 0 || newPeriod > MAX_PERIOD) return false; 77 | uint32_t newValue = (float)(F_BUS / 1000000) * newPeriod + 0.5; 78 | if (newValue < 40) return false; 79 | return beginCycles(newISR, newValue); 80 | } 81 | bool begin(ISR newISR, double newPeriod) { 82 | return begin(newISR, (float)newPeriod); 83 | } 84 | void end(); 85 | void priority(uint8_t n) { 86 | nvic_priority = n; 87 | if (PIT_enabled) NVIC_SET_PRIORITY(IRQ_PIT_CH, n); 88 | } 89 | #if defined(KINETISK) 90 | friend void pit0_isr(); 91 | friend void pit1_isr(); 92 | friend void pit2_isr(); 93 | friend void pit3_isr(); 94 | #elif defined(KINETISL) 95 | friend void pit_isr(); 96 | #endif 97 | }; 98 | 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library 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 GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #ifdef __cplusplus 24 | 25 | #include "new.h" 26 | 27 | class Print; 28 | 29 | /** The Printable class provides a way for new classes to allow themselves to be printed. 30 | By deriving from Printable and implementing the printTo method, it will then be possible 31 | for users to print out instances of this class by passing them into the usual 32 | Print::print and Print::println methods. 33 | */ 34 | class Printable 35 | { 36 | public: 37 | virtual size_t printTo(Print& p) const = 0; 38 | }; 39 | 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | teensy-braids 2 | ============= 3 | 4 | A port of the Mutable Instruments Braids to the Teensy board 5 | 6 | This project extracts the Mutable Instruments Braids macro oscillator and uses the analog output (pin A14) of the teensy as audio output. 7 | 8 | Once flashed, the Teensy receives MIDI-USB messages. The oscillator produces sound continuously and it changes the pitch based on the note-on message. The oscillator type, color and timbre are controlled with the messages CC32, CC33 and CC34 respectively. 9 | 10 | You can find the code in the main.cpp file. 11 | 12 | ============= 13 | 14 | ### Compile 15 | 16 | First install the Teensyduino tools. The define the variable ARDUINOPATH. In my case for OSX: 17 | 18 | ``` 19 | $ export ARDUINOPATH=/Applications/Arduino.app/Contents/Java 20 | ``` 21 | 22 | then use make 23 | 24 | ``` 25 | $ make 26 | ``` 27 | this will automatically open the Teensy loader program. -------------------------------------------------------------------------------- /SeeedOLED.h: -------------------------------------------------------------------------------- 1 | /* 2 | SeeedOLED.h - SSD130x OLED Driver Library 3 | 2011 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author: Visweswara R 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef SeeedOLED_data_H 23 | #define SeeedOLED_data_H 24 | 25 | // SeeedOLED Instruction set addresses 26 | 27 | #if defined(ARDUINO) && ARDUINO >= 100 28 | #include "Arduino.h" 29 | #else 30 | #include 31 | #include "i2c_t3.h" 32 | #endif 33 | 34 | 35 | 36 | #define SeeedOLED_Max_X 127 //128 Pixels 37 | #define SeeedOLED_Max_Y 63 //64 Pixels 38 | 39 | #define PAGE_MODE 01 40 | #define HORIZONTAL_MODE 02 41 | 42 | 43 | #define SeeedOLED_Address 0x3c 44 | #define SeeedOLED_Command_Mode 0x80 45 | #define SeeedOLED_Data_Mode 0x40 46 | #define SeeedOLED_Display_Off_Cmd 0xAE 47 | #define SeeedOLED_Display_On_Cmd 0xAF 48 | #define SeeedOLED_Normal_Display_Cmd 0xA6 49 | #define SeeedOLED_Inverse_Display_Cmd 0xA7 50 | #define SeeedOLED_Activate_Scroll_Cmd 0x2F 51 | #define SeeedOLED_Dectivate_Scroll_Cmd 0x2E 52 | #define SeeedOLED_Set_Brightness_Cmd 0x81 53 | 54 | #define Scroll_Left 0x00 55 | #define Scroll_Right 0x01 56 | 57 | #define Scroll_2Frames 0x7 58 | #define Scroll_3Frames 0x4 59 | #define Scroll_4Frames 0x5 60 | #define Scroll_5Frames 0x0 61 | #define Scroll_25Frames 0x6 62 | #define Scroll_64Frames 0x1 63 | #define Scroll_128Frames 0x2 64 | #define Scroll_256Frames 0x3 65 | 66 | 67 | class SeeedOLED { 68 | 69 | public: 70 | 71 | char addressingMode; 72 | 73 | 74 | void init(void); 75 | 76 | void setNormalDisplay(); 77 | void setInverseDisplay(); 78 | 79 | void sendCommand(unsigned char command); 80 | void sendData(unsigned char Data); 81 | 82 | void setPageMode(); 83 | void setHorizontalMode(); 84 | 85 | void setTextXY(unsigned char Row, unsigned char Column); 86 | void clearDisplay(); 87 | void setBrightness(unsigned char Brightness); 88 | void putChar(unsigned char c); 89 | void putCharLine(unsigned char c,unsigned char i); 90 | void putString(const char *String); 91 | unsigned char putNumber(long n); 92 | unsigned char putFloat(float floatNumber,unsigned char decimal); 93 | unsigned char putFloat(float floatNumber); 94 | void drawBitmap(unsigned char *bitmaparray,int bytes); 95 | 96 | void setHorizontalScrollProperties(bool direction,unsigned char startPage, unsigned char endPage, unsigned char scrollSpeed); 97 | void activateScroll(); 98 | void deactivateScroll(); 99 | 100 | void displayOff(); 101 | void displayOn(); 102 | 103 | }; 104 | 105 | extern SeeedOLED SeeedOled; // SeeedOLED object 106 | 107 | #endif 108 | 109 | 110 | -------------------------------------------------------------------------------- /Server.h: -------------------------------------------------------------------------------- 1 | #if ARDUINO >= 100 2 | 3 | #ifndef server_h 4 | #define server_h 5 | 6 | class Server : public Print { 7 | public: 8 | virtual void begin() =0; 9 | }; 10 | 11 | #endif 12 | #endif 13 | -------------------------------------------------------------------------------- /Stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | Stream.h - base class for character-based streams. 3 | Copyright (c) 2010 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library 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 GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Stream_h 21 | #define Stream_h 22 | 23 | #include 24 | #include "Print.h" 25 | 26 | class Stream : public Print 27 | { 28 | public: 29 | Stream() : _timeout(1000), read_error(0) {} 30 | virtual int available() = 0; 31 | virtual int read() = 0; 32 | virtual int peek() = 0; 33 | virtual void flush() = 0; 34 | 35 | void setTimeout(unsigned long timeout); 36 | bool find(char *target); 37 | bool find(uint8_t *target) { return find ((char *)target); } 38 | bool find(char *target, size_t length); 39 | bool find(uint8_t *target, size_t length) { return find ((char *)target, length); } 40 | bool findUntil(char *target, char *terminator); 41 | bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); } 42 | bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); 43 | bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); } 44 | long parseInt(); 45 | long parseInt(char skipChar); 46 | float parseFloat(); 47 | float parseFloat(char skipChar); 48 | size_t readBytes(char *buffer, size_t length); 49 | size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); } 50 | size_t readBytesUntil(char terminator, char *buffer, size_t length); 51 | size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); } 52 | String readString(size_t max = 120); 53 | String readStringUntil(char terminator, size_t max = 120); 54 | int getReadError() { return read_error; } 55 | void clearReadError() { setReadError(0); } 56 | protected: 57 | void setReadError(int err = 1) { read_error = err; } 58 | unsigned long _timeout; 59 | private: 60 | char read_error; 61 | int timedRead(); 62 | int timedPeek(); 63 | int peekNextDigit(); 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /WConstants.h: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | -------------------------------------------------------------------------------- /WMath.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static uint32_t seed; 4 | 5 | void randomSeed(uint32_t newseed) 6 | { 7 | if (newseed > 0) seed = newseed; 8 | } 9 | 10 | void srandom(uint32_t newseed) 11 | { 12 | seed = newseed; 13 | } 14 | 15 | uint32_t random(void) 16 | { 17 | int32_t hi, lo, x; 18 | 19 | // the algorithm used in avr-libc 1.6.4 20 | x = seed; 21 | if (x == 0) x = 123459876; 22 | hi = x / 127773; 23 | lo = x % 127773; 24 | x = 16807 * lo - 2836 * hi; 25 | if (x < 0) x += 0x7FFFFFFF; 26 | seed = x; 27 | return x; 28 | } 29 | 30 | uint32_t random(uint32_t howbig) 31 | { 32 | if (howbig == 0) return 0; 33 | return random() % howbig; 34 | } 35 | 36 | int32_t random(int32_t howsmall, int32_t howbig) 37 | { 38 | if (howsmall >= howbig) return howsmall; 39 | int32_t diff = howbig - howsmall; 40 | return random(diff) + howsmall; 41 | } 42 | 43 | long map(long x, long in_min, long in_max, long out_min, long out_max) 44 | { 45 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 46 | } 47 | 48 | unsigned int makeWord(unsigned int w) { return w; } 49 | unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } 50 | 51 | -------------------------------------------------------------------------------- /WProgram.h: -------------------------------------------------------------------------------- 1 | #ifndef WProgram_h 2 | #define WProgram_h 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // some libraries and sketches depend on this 9 | // AVR stuff, assuming Arduino.h or WProgram.h 10 | // automatically includes it... 11 | #include 12 | #include 13 | 14 | #include "avr_functions.h" 15 | #include "wiring.h" 16 | #include "HardwareSerial.h" 17 | 18 | #define DMAMEM __attribute__ ((section(".dmabuffers"), used)) 19 | #define FASTRUN __attribute__ ((section(".fastrun"), noinline, noclone )) 20 | 21 | #ifdef __cplusplus 22 | 23 | #include "avr_emulation.h" 24 | #include "usb_serial.h" 25 | #include "usb_seremu.h" 26 | #include "usb_keyboard.h" 27 | #include "usb_mouse.h" 28 | #include "usb_joystick.h" 29 | #include "usb_midi.h" 30 | #include "usb_rawhid.h" 31 | #include "usb_flightsim.h" 32 | #include "usb_mtp.h" 33 | #include "usb_undef.h" // do not allow usb_desc.h stuff to leak to user programs 34 | 35 | //#include "WCharacter.h" 36 | #include "WString.h" 37 | #include "elapsedMillis.h" 38 | #include "IntervalTimer.h" 39 | 40 | uint16_t makeWord(uint16_t w); 41 | uint16_t makeWord(byte h, byte l); 42 | 43 | #define word(...) makeWord(__VA_ARGS__) 44 | 45 | unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); 46 | 47 | void tone(uint8_t pin, uint16_t frequency, uint32_t duration = 0); 48 | void noTone(uint8_t pin); 49 | 50 | // WMath prototypes 51 | uint32_t random(void); 52 | uint32_t random(uint32_t howbig); 53 | int32_t random(int32_t howsmall, int32_t howbig); 54 | void randomSeed(uint32_t newseed); 55 | void srandom(uint32_t newseed); 56 | long map(long, long, long, long, long); 57 | 58 | #include "pins_arduino.h" 59 | 60 | #endif // __cplusplus 61 | 62 | 63 | // Fast memcpy 64 | #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK66FX1M0__) 65 | #ifdef __cplusplus 66 | extern "C" { 67 | extern void *memcpy (void *dst, const void *src, size_t count); 68 | } 69 | #else 70 | extern void *memcpy (void *dst, const void *src, size_t count); 71 | #endif 72 | #endif 73 | 74 | 75 | #endif // WProgram_h 76 | -------------------------------------------------------------------------------- /arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 11. November 2010 5 | * $Revision: V1.0.2 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Version 1.0.2 2010/11/11 15 | * Documentation updated. 16 | * 17 | * Version 1.0.1 2010/10/05 18 | * Production release and review comments incorporated. 19 | * 20 | * Version 1.0.0 2010/09/20 21 | * Production release and review comments incorporated. 22 | * -------------------------------------------------------------------- */ 23 | 24 | #ifndef _ARM_COMMON_TABLES_H 25 | #define _ARM_COMMON_TABLES_H 26 | 27 | #include "arm_math.h" 28 | 29 | extern const uint16_t armBitRevTable[1024]; 30 | extern const q15_t armRecipTableQ15[64]; 31 | extern const q31_t armRecipTableQ31[64]; 32 | extern const q31_t realCoefAQ31[1024]; 33 | extern const q31_t realCoefBQ31[1024]; 34 | extern const float32_t twiddleCoef[6144]; 35 | extern const q31_t twiddleCoefQ31[6144]; 36 | extern const q15_t twiddleCoefQ15[6144]; 37 | 38 | #endif /* ARM_COMMON_TABLES_H */ 39 | -------------------------------------------------------------------------------- /avr/eeprom.h: -------------------------------------------------------------------------------- 1 | /* Simple compatibility headers for AVR code used with ARM chips 2 | * Copyright (c) 2015 Paul Stoffregen 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _AVR_EEPROM_H_ 24 | #define _AVR_EEPROM_H_ 1 25 | 26 | #include 27 | #include 28 | 29 | #include "avr_functions.h" 30 | 31 | #if defined(__MK20DX128__) || defined(__MK20DX256__) 32 | #define E2END 0x7FF 33 | #elif defined(__MKL26Z64__) 34 | #define E2END 0x7F 35 | #else 36 | #define E2END 0 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /avr/interrupt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/avr/interrupt.h -------------------------------------------------------------------------------- /avr/io.h: -------------------------------------------------------------------------------- 1 | /* Simple compatibility headers for AVR code used with ARM chips 2 | * Copyright (c) 2015 Paul Stoffregen 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #include "../avr_emulation.h" 24 | -------------------------------------------------------------------------------- /avr/power.h: -------------------------------------------------------------------------------- 1 | /* Simple compatibility headers for AVR code used with ARM chips 2 | * Copyright (c) 2015 Paul Stoffregen 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _AVR_POWER_H_ 24 | #define _AVR_POWER_H_ 1 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /avr/sleep.h: -------------------------------------------------------------------------------- 1 | /* Simple compatibility headers for AVR code used with ARM chips 2 | * Copyright (c) 2015 Paul Stoffregen 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef _AVR_SLEEP_H_ 24 | #define _AVR_SLEEP_H_ 1 25 | 26 | #define SLEEP_MODE_IDLE 0 27 | #define SLEEP_MODE_ADC 0 28 | #define SLEEP_MODE_PWR_DOWN 1 29 | #define SLEEP_MODE_PWR_SAVE 1 30 | #define SLEEP_MODE_STANDBY 1 31 | #define SLEEP_MODE_EXT_STANDBY 1 32 | 33 | #define set_sleep_mode(mode) // TODO: actually set the mode... 34 | #define sleep_enable() 35 | #define sleep_disable() 36 | #define sleep_cpu() (asm("wfi")) 37 | #define sleep_bod_disable() 38 | #define sleep_mode() sleep_cpu() 39 | 40 | // workaround for early versions of Nordic's BLE library 41 | // EIMSK moved to a dummy byte in avr_emulation... 42 | //#if defined(HAL_ACI_TL_H__) && defined(PLATFORM_H__) 43 | //#define EIMSK uint8_t EIMSKworkaround=0; EIMSKworkaround 44 | //#endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /avr/wdt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/avr/wdt.h -------------------------------------------------------------------------------- /avr_emulation.cpp: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | 32 | #include "avr_emulation.h" 33 | #include "SPIFIFO.h" 34 | 35 | uint8_t SPCRemulation::pinout = 0; 36 | #if defined(KINETISL) 37 | uint8_t SPCR1emulation::pinout = 0; 38 | #endif 39 | 40 | #ifdef HAS_SPIFIFO 41 | 42 | uint8_t SPIFIFOclass::pcs = 0; 43 | volatile uint8_t * SPIFIFOclass::reg = 0; 44 | 45 | #endif 46 | 47 | 48 | -------------------------------------------------------------------------------- /core_id.h: -------------------------------------------------------------------------------- 1 | #ifndef CORE_TEENSY 2 | #define CORE_TEENSY 3 | #endif 4 | -------------------------------------------------------------------------------- /envelope.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 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 | // You should have received a copy of the GNU General Public License 14 | // along with this program. If not, see . 15 | 16 | #ifndef BRAIDS_ENVELOPE_H_ 17 | #define BRAIDS_ENVELOPE_H_ 18 | 19 | #include "stmlib/stmlib.h" 20 | 21 | #include "stmlib/utils/dsp.h" 22 | 23 | #include "resources.h" 24 | 25 | namespace braids { 26 | 27 | using namespace stmlib; 28 | 29 | enum EnvelopeSegment { 30 | ENV_SEGMENT_ATTACK = 0, 31 | ENV_SEGMENT_DECAY = 1, 32 | ENV_SEGMENT_SUSTAIN = 2, 33 | ENV_SEGMENT_RELEASE = 3, 34 | ENV_SEGMENT_DEAD = 4, 35 | ENV_NUM_SEGMENTS, 36 | }; 37 | 38 | class Envelope { 39 | public: 40 | Envelope() { } 41 | ~Envelope() { } 42 | 43 | void Init() { 44 | target_[ENV_SEGMENT_ATTACK] = 65535; 45 | target_[ENV_SEGMENT_RELEASE] = 0; 46 | target_[ENV_SEGMENT_DEAD] = 0; 47 | 48 | increment_[ENV_SEGMENT_SUSTAIN] = 0; 49 | increment_[ENV_SEGMENT_DEAD] = 0; 50 | } 51 | 52 | inline EnvelopeSegment segment() const { 53 | return static_cast(segment_); 54 | } 55 | 56 | inline void Update(int32_t a, int32_t d, int32_t s, int32_t r) { 57 | increment_[ENV_SEGMENT_ATTACK] = lut_env_portamento_increments[a]; 58 | increment_[ENV_SEGMENT_DECAY] = lut_env_portamento_increments[d]; 59 | increment_[ENV_SEGMENT_RELEASE] = lut_env_portamento_increments[r]; 60 | target_[ENV_SEGMENT_DECAY] = s << 9; 61 | target_[ENV_SEGMENT_SUSTAIN] = target_[ENV_SEGMENT_DECAY]; 62 | } 63 | 64 | inline void Trigger(EnvelopeSegment segment) { 65 | if (segment == ENV_SEGMENT_DEAD) { 66 | value_ = 0; 67 | } 68 | a_ = value_; 69 | b_ = target_[segment]; 70 | segment_ = segment; 71 | phase_ = 0; 72 | } 73 | 74 | inline uint16_t Render() { 75 | uint32_t increment = increment_[segment_]; 76 | phase_ += increment; 77 | if (phase_ < increment) { 78 | value_ = Mix(a_, b_, 65535); 79 | Trigger(static_cast(segment_ + 1)); 80 | } 81 | if (increment_[segment_]) { 82 | value_ = Mix(a_, b_, Interpolate824(lut_env_expo, phase_)); 83 | } 84 | return value_; 85 | } 86 | 87 | inline uint16_t value() const { return value_; } 88 | 89 | private: 90 | // Phase increments for each segment. 91 | uint32_t increment_[ENV_NUM_SEGMENTS]; 92 | 93 | // Value that needs to be reached at the end of each segment. 94 | uint16_t target_[ENV_NUM_SEGMENTS]; 95 | 96 | // Pointer to the shape table. 97 | const uint16_t* shape_[ENV_NUM_SEGMENTS]; 98 | 99 | // Current segment. 100 | size_t segment_; 101 | 102 | // Start and end value of the current segment. 103 | uint16_t a_; 104 | uint16_t b_; 105 | uint16_t value_; 106 | 107 | uint32_t phase_increment_; 108 | uint32_t phase_; 109 | 110 | DISALLOW_COPY_AND_ASSIGN(Envelope); 111 | }; 112 | 113 | } // namespace braids 114 | 115 | #endif // BRAIDS_ENVELOPE_H_ 116 | -------------------------------------------------------------------------------- /macro_oscillator.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Macro-oscillator entry point. 28 | 29 | #ifndef BRAIDS_MACRO_OSCILLATOR_H_ 30 | #define BRAIDS_MACRO_OSCILLATOR_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | #include 35 | 36 | #include "analog_oscillator.h" 37 | #include "digital_oscillator.h" 38 | #include "resources.h" 39 | #include "settings.h" 40 | 41 | namespace braids { 42 | 43 | class MacroOscillator { 44 | public: 45 | typedef void (MacroOscillator::*RenderFn)(const uint8_t*, int16_t*, uint8_t); 46 | 47 | MacroOscillator() { } 48 | ~MacroOscillator() { } 49 | 50 | inline void Init() { 51 | analog_oscillator_[0].Init(); 52 | analog_oscillator_[1].Init(); 53 | digital_oscillator_.Init(); 54 | } 55 | 56 | inline void set_shape(MacroOscillatorShape shape) { 57 | if (shape != shape_) { 58 | Strike(); 59 | } 60 | shape_ = shape; 61 | } 62 | 63 | inline void set_pitch(int16_t pitch) { 64 | pitch_ = pitch; 65 | } 66 | 67 | inline int16_t pitch() const { return pitch_; } 68 | 69 | inline void set_parameters( 70 | int16_t parameter_1, 71 | int16_t parameter_2) { 72 | parameter_[0] = parameter_1; 73 | parameter_[1] = parameter_2; 74 | } 75 | 76 | inline void Strike() { 77 | digital_oscillator_.Strike(); 78 | } 79 | 80 | void Render(const uint8_t* sync_buffer, int16_t* buffer, uint8_t size); 81 | 82 | private: 83 | void RenderCSaw(const uint8_t*, int16_t*, uint8_t); 84 | void RenderMorph(const uint8_t*, int16_t*, uint8_t); 85 | void RenderSawSquare(const uint8_t*, int16_t*, uint8_t); 86 | void RenderSquareSync(const uint8_t*, int16_t*, uint8_t); 87 | void RenderSineTriangle(const uint8_t*, int16_t*, uint8_t); 88 | void RenderBuzz(const uint8_t*, int16_t*, uint8_t); 89 | void RenderDigital(const uint8_t*, int16_t*, uint8_t); 90 | void RenderSawComb(const uint8_t*, int16_t*, uint8_t); 91 | void RenderTriple(const uint8_t*, int16_t*, uint8_t); 92 | 93 | int16_t parameter_[2]; 94 | int16_t previous_parameter_[2]; 95 | int16_t pitch_; 96 | uint8_t sync_buffer_[25]; 97 | int16_t temp_buffer_[25]; 98 | int32_t lp_state_; 99 | 100 | AnalogOscillator analog_oscillator_[3]; 101 | DigitalOscillator digital_oscillator_; 102 | 103 | MacroOscillatorShape shape_; 104 | static RenderFn fn_table_[]; 105 | 106 | DISALLOW_COPY_AND_ASSIGN(MacroOscillator); 107 | }; 108 | 109 | } // namespace braids 110 | 111 | #endif // BRAIDS_MACRO_OSCILLATOR_H_ 112 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var midi = require('midi'); 4 | 5 | output = new midi.output(); 6 | 7 | var device = 'Teensy'; 8 | /* Search the output port */ 9 | var ports = output.getPortCount(); 10 | for (var i = 0; i < ports; i++) { 11 | name = output.getPortName(i); 12 | if(name.indexOf(device)>-1){ 13 | output.openPort(i); 14 | console.log('Opening output '+name); 15 | break; 16 | } 17 | } 18 | 19 | pitch = 32; 20 | p1 = 0; 21 | p2 = 0; 22 | shape = 0; 23 | setInterval( 24 | function(){ 25 | pitch = pitch + 12; 26 | if(pitch>64) pitch = 32; 27 | 28 | output.sendMessage([0x90,pitch,100]); 29 | setTimeout( 30 | function(){ 31 | output.sendMessage([0x90,pitch,0]); 32 | //output.sendMessage([0xB0,33,p1]); 33 | //output.sendMessage([0xB0,34,p2]); 34 | },50); 35 | 36 | },300); 37 | 38 | setInterval( 39 | function(){ 40 | shape = Math.floor((Math.random() * 128)); 41 | p1 = Math.floor((Math.random() * 128)); 42 | p2 = Math.floor((Math.random() * 128)); 43 | //output.sendMessage([0xB0,32,shape]); 44 | //output.sendMessage([0xB0,33,p1]); 45 | //output.sendMessage([0xB0,34,p2]); 46 | },3000); -------------------------------------------------------------------------------- /make: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/make -------------------------------------------------------------------------------- /math_helper.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 29. November 2010 5 | * $Revision: V1.0.3 6 | * 7 | * Project: CMSIS DSP Library 8 | * 9 | * Title: math_helper.h 10 | * 11 | * 12 | * Description: Prototypes of all helper functions required. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Version 1.0.3 2010/11/29 17 | * Re-organized the CMSIS folders and updated documentation. 18 | * 19 | * Version 1.0.2 2010/11/11 20 | * Documentation updated. 21 | * 22 | * Version 1.0.1 2010/10/05 23 | * Production release and review comments incorporated. 24 | * 25 | * Version 1.0.0 2010/09/20 26 | * Production release and review comments incorporated. 27 | * 28 | * Version 0.0.7 2010/06/10 29 | * Misra-C changes done 30 | * -------------------------------------------------------------------- */ 31 | 32 | 33 | #include "arm_math.h" 34 | 35 | #ifndef MATH_HELPER_H 36 | #define MATH_HELPER_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" 40 | { 41 | #endif 42 | 43 | float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize); 44 | void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples); 45 | void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits); 46 | void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits); 47 | void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples); 48 | void arm_float_to_q29(float *pIn, q31_t *pOut, uint32_t numSamples); 49 | void arm_float_to_q28(float *pIn, q31_t *pOut, uint32_t numSamples); 50 | void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples); 51 | void arm_clip_f32(float *pIn, uint32_t numSamples); 52 | uint32_t arm_calc_guard_bits(uint32_t num_adds); 53 | void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits); 54 | uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples); 55 | uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples); 56 | uint32_t arm_calc_2pow(uint32_t guard_bits); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /mk20dx128.h: -------------------------------------------------------------------------------- 1 | #ifndef _mk20dx128_h_ 2 | #define _mk20dx128_h_ 3 | #include "kinetis.h" // mk20dx128.h renamed to kinetis.h 4 | #endif 5 | -------------------------------------------------------------------------------- /mk20dx128.ld: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | MEMORY 32 | { 33 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K 34 | RAM (rwx) : ORIGIN = 0x1FFFE000, LENGTH = 16K 35 | } 36 | 37 | 38 | SECTIONS 39 | { 40 | .text : { 41 | . = 0; 42 | KEEP(*(.vectors)) 43 | *(.startup*) 44 | /* TODO: does linker detect startup overflow onto flashconfig? */ 45 | . = 0x400; 46 | KEEP(*(.flashconfig*)) 47 | *(.text*) 48 | *(.rodata*) 49 | . = ALIGN(4); 50 | KEEP(*(.init)) 51 | . = ALIGN(4); 52 | __preinit_array_start = .; 53 | KEEP (*(.preinit_array)) 54 | __preinit_array_end = .; 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } > FLASH = 0xFF 60 | 61 | .ARM.exidx : { 62 | __exidx_start = .; 63 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 64 | __exidx_end = .; 65 | } > FLASH 66 | _etext = .; 67 | 68 | .usbdescriptortable (NOLOAD) : { 69 | /* . = ORIGIN(RAM); */ 70 | . = ALIGN(512); 71 | *(.usbdescriptortable*) 72 | } > RAM 73 | 74 | .dmabuffers (NOLOAD) : { 75 | . = ALIGN(4); 76 | *(.dmabuffers*) 77 | } > RAM 78 | 79 | .usbbuffers (NOLOAD) : { 80 | . = ALIGN(4); 81 | *(.usbbuffers*) 82 | } > RAM 83 | 84 | .data : AT (_etext) { 85 | . = ALIGN(4); 86 | _sdata = .; 87 | *(.fastrun*) 88 | *(.data*) 89 | . = ALIGN(4); 90 | _edata = .; 91 | } > RAM 92 | 93 | .noinit (NOLOAD) : { 94 | *(.noinit*) 95 | } > RAM 96 | 97 | .bss : { 98 | . = ALIGN(4); 99 | _sbss = .; 100 | __bss_start__ = .; 101 | *(.bss*) 102 | *(COMMON) 103 | . = ALIGN(4); 104 | _ebss = .; 105 | __bss_end = .; 106 | __bss_end__ = .; 107 | } > RAM 108 | 109 | _estack = ORIGIN(RAM) + LENGTH(RAM); 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /mk20dx256.ld: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | MEMORY 32 | { 33 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K 34 | RAM (rwx) : ORIGIN = 0x1FFF8000, LENGTH = 64K 35 | } 36 | 37 | 38 | SECTIONS 39 | { 40 | .text : { 41 | . = 0; 42 | KEEP(*(.vectors)) 43 | *(.startup*) 44 | /* TODO: does linker detect startup overflow onto flashconfig? */ 45 | . = 0x400; 46 | KEEP(*(.flashconfig*)) 47 | *(.text*) 48 | *(.rodata*) 49 | . = ALIGN(4); 50 | KEEP(*(.init)) 51 | . = ALIGN(4); 52 | __preinit_array_start = .; 53 | KEEP (*(.preinit_array)) 54 | __preinit_array_end = .; 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } > FLASH = 0xFF 60 | 61 | .ARM.exidx : { 62 | __exidx_start = .; 63 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 64 | __exidx_end = .; 65 | } > FLASH 66 | _etext = .; 67 | 68 | .usbdescriptortable (NOLOAD) : { 69 | /* . = ORIGIN(RAM); */ 70 | . = ALIGN(512); 71 | *(.usbdescriptortable*) 72 | } > RAM 73 | 74 | .dmabuffers (NOLOAD) : { 75 | . = ALIGN(4); 76 | *(.dmabuffers*) 77 | } > RAM 78 | 79 | .usbbuffers (NOLOAD) : { 80 | . = ALIGN(4); 81 | *(.usbbuffers*) 82 | } > RAM 83 | 84 | .data : AT (_etext) { 85 | . = ALIGN(4); 86 | _sdata = .; 87 | *(.fastrun*) 88 | *(.data*) 89 | . = ALIGN(4); 90 | _edata = .; 91 | } > RAM 92 | 93 | .noinit (NOLOAD) : { 94 | *(.noinit*) 95 | } > RAM 96 | 97 | .bss : { 98 | . = ALIGN(4); 99 | _sbss = .; 100 | __bss_start__ = .; 101 | *(.bss*) 102 | *(COMMON) 103 | . = ALIGN(4); 104 | _ebss = .; 105 | __bss_end = .; 106 | __bss_end__ = .; 107 | } > RAM 108 | 109 | _estack = ORIGIN(RAM) + LENGTH(RAM); 110 | } 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /mk66fx1m0.ld: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | MEMORY 32 | { 33 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 1024K 34 | RAM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 256K 35 | } 36 | 37 | 38 | SECTIONS 39 | { 40 | .text : { 41 | . = 0; 42 | KEEP(*(.vectors)) 43 | *(.startup*) 44 | /* TODO: does linker detect startup overflow onto flashconfig? */ 45 | . = 0x400; 46 | KEEP(*(.flashconfig*)) 47 | *(.text*) 48 | *(.rodata*) 49 | . = ALIGN(4); 50 | KEEP(*(.init)) 51 | . = ALIGN(4); 52 | __preinit_array_start = .; 53 | KEEP (*(.preinit_array)) 54 | __preinit_array_end = .; 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } > FLASH = 0xFF 60 | 61 | .ARM.exidx : { 62 | __exidx_start = .; 63 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 64 | __exidx_end = .; 65 | } > FLASH 66 | _etext = .; 67 | 68 | .usbdescriptortable (NOLOAD) : { 69 | /* . = ORIGIN(RAM); */ 70 | . = ALIGN(512); 71 | *(.usbdescriptortable*) 72 | } > RAM 73 | 74 | .dmabuffers (NOLOAD) : { 75 | . = ALIGN(4); 76 | *(.dmabuffers*) 77 | } > RAM 78 | 79 | .usbbuffers (NOLOAD) : { 80 | . = ALIGN(4); 81 | *(.usbbuffers*) 82 | } > RAM 83 | 84 | .data : AT (_etext) { 85 | . = ALIGN(4); 86 | _sdata = .; 87 | *(.fastrun*) 88 | *(.data*) 89 | . = ALIGN(4); 90 | _edata = .; 91 | } > RAM 92 | 93 | .noinit (NOLOAD) : { 94 | *(.noinit*) 95 | } > RAM 96 | 97 | .bss : { 98 | . = ALIGN(4); 99 | _sbss = .; 100 | __bss_start__ = .; 101 | *(.bss*) 102 | *(COMMON) 103 | . = ALIGN(4); 104 | _ebss = .; 105 | __bss_end = .; 106 | __bss_end__ = .; 107 | } > RAM 108 | 109 | _estack = ORIGIN(RAM) + LENGTH(RAM); 110 | } 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /mkl26z64.ld: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2014 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | MEMORY 32 | { 33 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 62K 34 | RAM (rwx) : ORIGIN = 0x1FFFF800, LENGTH = 8K 35 | } 36 | 37 | 38 | SECTIONS 39 | { 40 | .text : { 41 | . = 0; 42 | KEEP(*(.vectors)) 43 | *(.startup*) 44 | /* TODO: does linker detect startup overflow onto flashconfig? */ 45 | . = 0x400; 46 | KEEP(*(.flashconfig*)) 47 | *(.text*) 48 | *(.rodata*) 49 | . = ALIGN(4); 50 | KEEP(*(.init)) 51 | . = ALIGN(4); 52 | __preinit_array_start = .; 53 | KEEP (*(.preinit_array)) 54 | __preinit_array_end = .; 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } > FLASH = 0xFF 60 | 61 | .ARM.exidx : { 62 | __exidx_start = .; 63 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 64 | __exidx_end = .; 65 | } > FLASH 66 | _etext = .; 67 | 68 | .usbdescriptortable (NOLOAD) : { 69 | /* . = ORIGIN(RAM); */ 70 | . = ALIGN(512); 71 | *(.usbdescriptortable*) 72 | } > RAM 73 | 74 | .dmabuffers (NOLOAD) : { 75 | . = ALIGN(4); 76 | *(.dmabuffers*) 77 | } > RAM 78 | 79 | .usbbuffers (NOLOAD) : { 80 | . = ALIGN(4); 81 | *(.usbbuffers*) 82 | } > RAM 83 | 84 | .data : AT (_etext) { 85 | . = ALIGN(4); 86 | _sdata = .; 87 | *(.fastrun*) 88 | *(.data*) 89 | . = ALIGN(4); 90 | _edata = .; 91 | } > RAM 92 | 93 | .noinit (NOLOAD) : { 94 | *(.noinit*) 95 | } > RAM 96 | 97 | .bss : { 98 | . = ALIGN(4); 99 | _sbss = .; 100 | __bss_start__ = .; 101 | *(.bss*) 102 | *(COMMON) 103 | . = ALIGN(4); 104 | _ebss = .; 105 | __bss_end = .; 106 | __bss_end__ = .; 107 | } > RAM 108 | 109 | _estack = ORIGIN(RAM) + LENGTH(RAM); 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /my_environment_back.sh: -------------------------------------------------------------------------------- 1 | export ARDUINOPATH=/Applications/Arduino.app/Contents/Java 2 | -------------------------------------------------------------------------------- /new.cpp: -------------------------------------------------------------------------------- 1 | #include "new.h" 2 | 3 | void * operator new(size_t size) 4 | { 5 | return malloc(size); 6 | } 7 | 8 | void * operator new[](size_t size) 9 | { 10 | return malloc(size); 11 | } 12 | 13 | void operator delete(void * ptr) 14 | { 15 | free(ptr); 16 | } 17 | 18 | void operator delete[](void * ptr) 19 | { 20 | free(ptr); 21 | } 22 | 23 | //int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; 24 | //void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; 25 | //void __cxa_guard_abort (__guard *) {}; 26 | 27 | //void __cxa_pure_virtual(void) {}; 28 | 29 | -------------------------------------------------------------------------------- /new.h: -------------------------------------------------------------------------------- 1 | /* Header to define new/delete operators as they aren't provided by avr-gcc by default 2 | Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 3 | */ 4 | 5 | #ifndef NEW_H 6 | #define NEW_H 7 | 8 | #ifdef __cplusplus 9 | 10 | #include 11 | 12 | void * operator new(size_t size); 13 | void * operator new[](size_t size); 14 | void operator delete(void * ptr); 15 | void operator delete[](void * ptr); 16 | 17 | __extension__ typedef int __guard __attribute__((mode (__DI__))); 18 | 19 | extern "C" int __cxa_guard_acquire(__guard *); 20 | extern "C" void __cxa_guard_release (__guard *); 21 | extern "C" void __cxa_guard_abort (__guard *); 22 | extern "C" void __cxa_pure_virtual(void); 23 | 24 | #endif // __cplusplus 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /nonstd.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "avr_functions.h" 32 | #include 33 | #include 34 | 35 | 36 | char * ultoa(unsigned long val, char *buf, int radix) 37 | { 38 | unsigned digit; 39 | int i=0, j; 40 | char t; 41 | 42 | while (1) { 43 | digit = val % radix; 44 | buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10); 45 | val /= radix; 46 | if (val == 0) break; 47 | i++; 48 | } 49 | buf[i + 1] = 0; 50 | for (j=0; j < i; j++, i--) { 51 | t = buf[j]; 52 | buf[j] = buf[i]; 53 | buf[i] = t; 54 | } 55 | return buf; 56 | } 57 | 58 | char * ltoa(long val, char *buf, int radix) 59 | { 60 | if (val >= 0) { 61 | return ultoa(val, buf, radix); 62 | } else { 63 | buf[0] = '-'; 64 | ultoa(-val, buf + 1, radix); 65 | return buf; 66 | } 67 | } 68 | 69 | char * dtostrf(float val, int width, unsigned int precision, char *buf) 70 | { 71 | int decpt, sign, reqd, pad; 72 | const char *s, *e; 73 | char *p; 74 | 75 | s = fcvt(val, precision, &decpt, &sign); 76 | if (precision == 0 && decpt == 0) { 77 | s = (*s < '5') ? "0" : "1"; 78 | reqd = 1; 79 | } else { 80 | reqd = strlen(s); 81 | if (reqd > decpt) reqd++; 82 | if (decpt == 0) reqd++; 83 | } 84 | if (sign) reqd++; 85 | p = buf; 86 | e = p + reqd; 87 | pad = width - reqd; 88 | if (pad > 0) { 89 | e += pad; 90 | while (pad-- > 0) *p++ = ' '; 91 | } 92 | if (sign) *p++ = '-'; 93 | if (decpt == 0 && precision > 0) { 94 | *p++ = '0'; 95 | *p++ = '.'; 96 | } 97 | else if (decpt < 0 && precision > 0) { 98 | *p++ = '0'; 99 | *p++ = '.'; 100 | e++; 101 | while ( decpt < 0 ) { 102 | decpt++; 103 | *p++ = '0'; 104 | } 105 | } 106 | while (p < e) { 107 | *p++ = *s++; 108 | if (p == e) break; 109 | if (--decpt == 0) *p++ = '.'; 110 | } 111 | if (width < 0) { 112 | pad = (reqd + width) * -1; 113 | while (pad-- > 0) *p++ = ' '; 114 | } 115 | *p = 0; 116 | 117 | //char format[20]; 118 | //sprintf(format, "%%%d.%df", width, precision); 119 | //sprintf(buf, format, val); 120 | return buf; 121 | } 122 | 123 | -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'install' ] 3 | 2 info using npm@1.4.9 4 | 3 info using node@v0.10.28 5 | 4 verbose node symlink /usr/bin/node 6 | 5 error install Couldn't read dependencies 7 | 6 error package.json ENOENT, open '/home/leonardo/Development/blinky/package.json' 8 | 6 error package.json This is most likely not a problem with npm itself. 9 | 6 error package.json npm can't find a package.json file in your current directory. 10 | 7 error System Linux 3.2.0-63-generic-pae 11 | 8 error command "/usr/bin/node" "/usr/bin/npm" "install" 12 | 9 error cwd /home/leonardo/Development/blinky 13 | 10 error node -v v0.10.28 14 | 11 error npm -v 1.4.9 15 | 12 error path /home/leonardo/Development/blinky/package.json 16 | 13 error code ENOPACKAGEJSON 17 | 14 error errno 34 18 | 15 verbose exit [ 34, true ] 19 | -------------------------------------------------------------------------------- /random.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Random number generator. 28 | 29 | #include "stmlib/utils/random.h" 30 | 31 | namespace stmlib { 32 | 33 | /* static */ 34 | uint32_t Random::rng_state_ = 0x21; 35 | 36 | } // namespace stmlib 37 | -------------------------------------------------------------------------------- /ser_print.c: -------------------------------------------------------------------------------- 1 | #include "kinetis.h" 2 | #include "ser_print.h" 3 | 4 | #ifdef KINETISL 5 | 6 | // Simple polling-only Serial1 support for Teensy-LC 7 | 8 | // this is really only useful for extremely low-level troubleshooting 9 | 10 | void ser_write(uint8_t c) 11 | { 12 | while ((UART0_S1 & UART_S1_TDRE) == 0) /* wait */ ; 13 | UART0_D = c; 14 | } 15 | 16 | void ser_print(const char *p) 17 | { 18 | while (*p) { 19 | char c = *p++; 20 | if (c == '\n') ser_write('\r'); 21 | ser_write(c); 22 | } 23 | } 24 | 25 | static void ser_print_hex1(unsigned int n) 26 | { 27 | n &= 15; 28 | if (n < 10) { 29 | ser_write('0' + n); 30 | } else { 31 | ser_write('A' - 10 + n); 32 | } 33 | } 34 | 35 | void ser_print_hex(unsigned int n) 36 | { 37 | ser_print_hex1(n >> 4); 38 | ser_print_hex1(n); 39 | } 40 | 41 | void ser_print_hex32(unsigned int n) 42 | { 43 | ser_print_hex(n >> 24); 44 | ser_print_hex(n >> 16); 45 | ser_print_hex(n >> 8); 46 | ser_print_hex(n); 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /ser_print.h: -------------------------------------------------------------------------------- 1 | 2 | #ifdef __cplusplus 3 | extern "C"{ 4 | #endif 5 | void ser_print(const char *p); 6 | void ser_print_hex(unsigned int n); 7 | void ser_print_hex32(unsigned int n); 8 | #ifdef __cplusplus 9 | } // extern "C" 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /stmlib/.gitignore: -------------------------------------------------------------------------------- 1 | # Precompiled python modules 2 | *.pyc 3 | 4 | # LaTeX compiled file 5 | *.pdf 6 | *.log 7 | *.aux 8 | 9 | # OS X crap 10 | .DS_Stor? 11 | -------------------------------------------------------------------------------- /stmlib/LICENSE: -------------------------------------------------------------------------------- 1 | Except when noted otherwise, all code is copyright Olivier Gillet and is 2 | released under the MIT License with the following notice: 3 | 4 | Copyright 2012 Olivier Gillet. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | ------------------------------------------------------------------------------- 25 | 26 | The code in third_party/STM is from STMicroelectronics, and released with the 27 | following notice: 28 | 29 | THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 30 | WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 31 | AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 32 | INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 33 | CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 34 | INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 35 | 36 | ------------------------------------------------------------------------------- 37 | 38 | The code in programming/serial is from Ivan A-R, and released under the GPL with 39 | the following notice: 40 | 41 | Author: Ivan A-R 42 | Project page: http://tuxotronic.org/wiki/projects/stm32loader 43 | 44 | This file is part of stm32loader. 45 | 46 | stm32loader is free software; you can redistribute it and/or modify it under 47 | the terms of the GNU General Public License as published by the Free 48 | Software Foundation; either version 3, or (at your option) any later 49 | version. 50 | 51 | stm32loader is distributed in the hope that it will be useful, but WITHOUT ANY 52 | WARRANTY; without even the implied warranty of MERCHANTABILITY or 53 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54 | for more details. 55 | 56 | You should have received a copy of the GNU General Public License 57 | along with stm32loader; see the file COPYING3. If not see 58 | . -------------------------------------------------------------------------------- /stmlib/README.md: -------------------------------------------------------------------------------- 1 | Mutable Instruments' project template, makefile, and libraries for STM32F 2 | projects. 3 | 4 | See LICENSE for licensing information. 5 | 6 | More to come! -------------------------------------------------------------------------------- /stmlib/algorithms/pattern_predictor.h: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Pattern predictor for synchronization to drum patterns or clocks with swing. 28 | 29 | #ifndef STMLIB_ALGORITHMS_PATTERN_PREDICTOR_H_ 30 | #define STMLIB_ALGORITHMS_PATTERN_PREDICTOR_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | #include 35 | #include 36 | 37 | namespace stmlib { 38 | 39 | template 40 | class PatternPredictor { 41 | public: 42 | PatternPredictor() { } 43 | 44 | void Init() { 45 | last_prediction_ = 0; 46 | history_pointer_ = 0; 47 | std::fill(&history_[0], &history_[history_size], 0); 48 | } 49 | 50 | uint32_t Predict(uint32_t value) { 51 | // Record the incoming value. 52 | history_[history_pointer_] = value; 53 | 54 | // Try various candidate periods 55 | uint8_t best_score = 0; 56 | uint8_t period = 0; 57 | for (uint8_t t = 1; t < max_candidate_period; ++t) { 58 | uint8_t score = 0; 59 | for (uint8_t k = 0; k < history_size; ++k) { 60 | uint32_t i = history_pointer_ + 2 * history_size - k; 61 | uint32_t j = i - t; 62 | i = i % history_size; 63 | j = j % history_size; 64 | uint32_t error = abs(static_cast(history_[i] - history_[j])); 65 | if (error < (history_[i] >> 4)) { 66 | ++score; 67 | } 68 | } 69 | if (score >= best_score) { 70 | best_score = score; 71 | period = t; 72 | } 73 | } 74 | history_pointer_ = (history_pointer_ + 1) % history_size; 75 | uint32_t new_prediction = \ 76 | history_[(history_pointer_ - period + history_size) % history_size]; 77 | 78 | uint32_t error = abs(static_cast(value - last_prediction_)); 79 | bool prediction_was_good = error < (value >> 4); 80 | last_prediction_ = new_prediction; 81 | return prediction_was_good ? new_prediction : value; 82 | } 83 | 84 | private: 85 | uint32_t history_[history_size]; 86 | uint32_t history_pointer_; 87 | uint32_t last_prediction_; 88 | 89 | DISALLOW_COPY_AND_ASSIGN(PatternPredictor); 90 | }; 91 | 92 | } // namespace stmlib 93 | 94 | #endif // STMLIB_ALGORITHMS_PATTERN_PREDICTOR_H_ 95 | -------------------------------------------------------------------------------- /stmlib/algorithms/tiny_map.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // A rather inefficient (lookup and insertion in O(n)) map. Useful for storing 28 | // very small mappings (say about 16 values). 29 | 30 | #ifndef STMLIB_ALGORITHMS_TINY_MAP_H_ 31 | #define STMLIB_ALGORITHMS_TINY_MAP_H_ 32 | 33 | #include "stmlib/stmlib.h" 34 | 35 | #include 36 | 37 | namespace stmlib { 38 | 39 | template< 40 | typename Key, 41 | typename Value, 42 | uint8_t capacity, 43 | uint8_t EMPTY = 0xff> 44 | class TinyMap { 45 | public: 46 | struct Entry { 47 | Key key; 48 | Value value; 49 | }; 50 | 51 | TinyMap() { } 52 | ~TinyMap() { } 53 | 54 | void Init() { 55 | Clear(); 56 | } 57 | 58 | void Put(Key key, Value value) { 59 | Entry* entry = Search(key); 60 | if (entry == NULL) { 61 | entry = SearchFreeSlot(); 62 | } 63 | if (entry == NULL) { 64 | entry = &map_[0]; 65 | } 66 | entry->key = key; 67 | entry->value = value; 68 | // Speed up retrieval for next query, in the very common case that when 69 | // element is inserted, the next query is for this same element. 70 | if (value != EMPTY) { 71 | recent_search_ = entry; 72 | } else { 73 | recent_delete_ = entry; 74 | } 75 | } 76 | 77 | const Entry* Find(uint8_t key) { 78 | return Search(key); 79 | } 80 | 81 | void Clear() { 82 | memset(map_, EMPTY, capacity * sizeof(Entry)); 83 | recent_search_ = recent_delete_ = &map_[0]; 84 | } 85 | 86 | private: 87 | Entry* Search(Key key) { 88 | if (recent_search_->key == key) { 89 | return recent_search_; 90 | } 91 | for (uint8_t i = 0; i < capacity; ++i) { 92 | if (map_[i].key == key) { 93 | recent_search_ = &map_[i]; 94 | return recent_search_; 95 | } 96 | } 97 | return NULL; 98 | } 99 | 100 | Entry* SearchFreeSlot() { 101 | if (recent_delete_->value == EMPTY) { 102 | return recent_delete_; 103 | } 104 | for (uint8_t i = 0; i < capacity; ++i) { 105 | if (map_[i].value == EMPTY) { 106 | recent_delete_ = &map_[i]; 107 | return recent_delete_; 108 | } 109 | } 110 | return NULL; 111 | } 112 | 113 | Entry map_[capacity]; 114 | Entry* recent_search_; 115 | Entry* recent_delete_; 116 | DISALLOW_COPY_AND_ASSIGN(TinyMap); 117 | }; 118 | 119 | } // namespace stmlib 120 | 121 | #endif // STMLIB_ALGORITHMS_TINY_MAP_H_ 122 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_cl.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_cl_application.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08004000, LENGTH = 240K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_cl_application_small.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08001000, LENGTH = 252K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_hd.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_hd_application.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08004000, LENGTH = 496K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_hd_application_small.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08001000, LENGTH = 508K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | KEEP (*(.init)) 20 | KEEP (*(.fini)) 21 | _etext = .; 22 | _sidata = .; 23 | } > FLASH 24 | 25 | .data : AT (ADDR(.text) + SIZEOF(.text)) 26 | { 27 | _sdata = .; 28 | *(.ramtext*) 29 | . = ALIGN(4); 30 | *(.data*) 31 | _edata = .; 32 | } > RAM 33 | 34 | .bss : 35 | { 36 | _sstack = .; 37 | . = . + 512; 38 | _estack = .; 39 | _sbss = .; 40 | *(.bss*) 41 | *(COMMON) 42 | _ebss = .; 43 | } > RAM 44 | } 45 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_md.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | *(.flashtext*) 20 | KEEP (*(.init)) 21 | KEEP (*(.fini)) 22 | _etext = .; 23 | _sidata = .; 24 | } > FLASH 25 | 26 | .data : AT (ADDR(.text) + SIZEOF(.text)) 27 | { 28 | _sdata = .; 29 | *(.ramtext*) 30 | . = ALIGN(4); 31 | *(.data*) 32 | _edata = .; 33 | } > RAM 34 | 35 | .bss : 36 | { 37 | _sstack = .; 38 | . = . + 512; 39 | _estack = .; 40 | _sbss = .; 41 | *(.bss*) 42 | *(COMMON) 43 | _ebss = .; 44 | } > RAM 45 | } 46 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_md_application.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08004000, LENGTH = 112K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | *(.flashtext*) 20 | KEEP (*(.init)) 21 | KEEP (*(.fini)) 22 | _etext = .; 23 | _sidata = .; 24 | } > FLASH 25 | 26 | .data : AT (ADDR(.text) + SIZEOF(.text)) 27 | { 28 | _sdata = .; 29 | *(.ramtext*) 30 | . = ALIGN(4); 31 | *(.data*) 32 | _edata = .; 33 | } > RAM 34 | 35 | .bss : 36 | { 37 | _sstack = .; 38 | . = . + 512; 39 | _estack = .; 40 | _sbss = .; 41 | *(.bss*) 42 | *(COMMON) 43 | _ebss = .; 44 | } > RAM 45 | } 46 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f10x_flash_md_application_small.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32F103R8T6 3 | */ 4 | 5 | MEMORY 6 | { 7 | FLASH (rx) : ORIGIN = 0x08001000, LENGTH = 124K 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 9 | } 10 | 11 | SECTIONS 12 | { 13 | .text : 14 | { 15 | _start = .; 16 | KEEP(*(.isr_vector)) 17 | *(.text*) 18 | *(.rodata*) 19 | *(.flashtext*) 20 | KEEP (*(.init)) 21 | KEEP (*(.fini)) 22 | _etext = .; 23 | _sidata = .; 24 | } > FLASH 25 | 26 | .data : AT (ADDR(.text) + SIZEOF(.text)) 27 | { 28 | _sdata = .; 29 | *(.ramtext*) 30 | . = ALIGN(4); 31 | *(.data*) 32 | _edata = .; 33 | } > RAM 34 | 35 | .bss : 36 | { 37 | _sstack = .; 38 | . = . + 512; 39 | _estack = .; 40 | _sbss = .; 41 | *(.bss*) 42 | *(COMMON) 43 | _ebss = .; 44 | } > RAM 45 | } 46 | -------------------------------------------------------------------------------- /stmlib/linker_scripts/stm32f4xx_flash.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Default linker script for STM32F4xx_1024K_192K 3 | */ 4 | 5 | ENTRY(Reset_Handler) 6 | 7 | _estack = 0x20020000; 8 | 9 | _Min_Heap_Size = 0; 10 | _Min_Stack_Size = 0x400; 11 | 12 | 13 | MEMORY 14 | { 15 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 16 | CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K 17 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1M-16K 18 | STORAGE (rx) : ORIGIN = 0x080fc000, LENGTH = 16K 19 | } 20 | 21 | SECTIONS 22 | { 23 | .isr_vector : 24 | { 25 | . = ALIGN(4); 26 | KEEP(*(.isr_vector)) /* Startup code */ 27 | . = ALIGN(4); 28 | } >FLASH 29 | 30 | .flashtext : 31 | { 32 | . = ALIGN(4); 33 | *(.flashtext) /* Startup code */ 34 | . = ALIGN(4); 35 | } >FLASH 36 | 37 | .text : 38 | { 39 | . = ALIGN(4); 40 | *(.text) /* remaining code */ 41 | *(.text.*) /* remaining code */ 42 | *(.rodata) /* read-only data (constants) */ 43 | *(.rodata*) 44 | *(.glue_7) 45 | *(.glue_7t) 46 | KEEP (*(.init)) 47 | KEEP (*(.fini)) 48 | . = ALIGN(4); 49 | _etext = .; 50 | _sidata = _etext; 51 | } >FLASH 52 | 53 | .data : AT ( _sidata ) 54 | { 55 | . = ALIGN(4); 56 | _sdata = . ; 57 | *(.ramtext*) 58 | . = ALIGN(4); 59 | *(.data*) 60 | *(.data.*) 61 | . = ALIGN(4); 62 | _edata = . ; 63 | } >RAM 64 | 65 | .bss : 66 | { 67 | . = ALIGN(4); 68 | _sbss = .; 69 | *(.bss) 70 | *(.bss*) 71 | *(COMMON) 72 | . = ALIGN(4); 73 | _ebss = . ; 74 | } >RAM 75 | 76 | PROVIDE ( end = _ebss ); 77 | PROVIDE ( _end = _ebss ); 78 | 79 | ._user_heap_stack : 80 | { 81 | . = ALIGN(4); 82 | PROVIDE ( end = . ); 83 | PROVIDE ( _end = . ); 84 | . = . + _Min_Heap_Size; 85 | . = . + _Min_Stack_Size; 86 | . = ALIGN(4); 87 | } >RAM 88 | 89 | /* CCM section, vars must be located here explicitly */ 90 | /* Example: int foo __attribute__ ((section (".ccmdata"))); */ 91 | .ccmdata (NOLOAD) : 92 | { 93 | . = ALIGN(4); 94 | *(.ccmdata) 95 | . = ALIGN(4); 96 | } >CCMRAM 97 | 98 | DISCARD : 99 | { 100 | libc.a ( * ) 101 | libm.a ( * ) 102 | libgcc.a ( * ) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/erase_f10x.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | stm32f1x mass_erase 0 24 | sleep 200 25 | reset 26 | sleep 200 27 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/erase_f4xx.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | stm32f2x mass_erase 0 24 | sleep 200 25 | reset 26 | sleep 200 27 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/interface.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | tcl_port 5555 24 | telnet_port 4444 25 | gdb_port 3333 26 | 27 | # Interface configuration 28 | interface ft2232 29 | ft2232_layout olimex-jtag 30 | 31 | # ARM-USB-OCD 32 | # ft2232_vid_pid 0x15BA 0x0003 33 | # ft2232_device_desc "Olimex OpenOCD JTAG" 34 | 35 | # ARM-USB-OCD-H 36 | ft2232_vid_pid 0x15BA 0x002b 37 | ft2232_device_desc "Olimex OpenOCD JTAG ARM-USB-OCD-H" 38 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/postlude.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | sleep 200 24 | reset run 25 | shutdown 26 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/prelude_f10x.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | init 24 | 25 | halt 26 | sleep 200 27 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/prelude_f4xx.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2012 Olivier Gillet. 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | # 21 | # See http://creativecommons.org/licenses/MIT/ for more information. 22 | 23 | init 24 | 25 | halt 26 | sleep 200 27 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/stm32f10x.cfg: -------------------------------------------------------------------------------- 1 | # script for stm32 2 | 3 | if { [info exists CHIPNAME] } { 4 | set _CHIPNAME $CHIPNAME 5 | } else { 6 | set _CHIPNAME stm32 7 | } 8 | 9 | if { [info exists ENDIAN] } { 10 | set _ENDIAN $ENDIAN 11 | } else { 12 | set _ENDIAN little 13 | } 14 | 15 | # Work-area is a space in RAM used for flash programming 16 | # By default use 8kB 17 | 18 | # set WORKAREASIZE 0x2000 19 | set WORKAREASIZE 0x5000 20 | 21 | if { [info exists WORKAREASIZE] } { 22 | set _WORKAREASIZE $WORKAREASIZE 23 | } else { 24 | set _WORKAREASIZE 0x4000 25 | } 26 | 27 | # JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz 28 | jtag_khz 1000 29 | 30 | jtag_nsrst_delay 200 31 | jtag_ntrst_delay 200 32 | 33 | reset_config trst_and_srst 34 | 35 | #jtag scan chain 36 | if { [info exists CPUTAPID ] } { 37 | set _CPUTAPID $CPUTAPID 38 | } else { 39 | # See STM Document RM0008 40 | # Section 26.6.3 41 | set _CPUTAPID 0x3ba00477 42 | } 43 | jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 44 | 45 | if { [info exists BSTAPID ] } { 46 | # FIXME this never gets used to override defaults... 47 | set _BSTAPID $BSTAPID 48 | } else { 49 | # See STM Document RM0008 50 | # Section 29.6.2 51 | # Low density devices, Rev A 52 | set _BSTAPID1 0x06412041 53 | # Medium density devices, Rev A 54 | set _BSTAPID2 0x06410041 55 | # Medium density devices, Rev B and Rev Z 56 | set _BSTAPID3 0x16410041 57 | # High density devices, Rev A 58 | set _BSTAPID4 0x06414041 59 | # Connectivity line devices, Rev A and Rev Z 60 | set _BSTAPID5 0x06418041 61 | # Connectivity line devices, Other revision? 62 | set _BSTAPID6 0x06420041 63 | } 64 | jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 -expected-id $_BSTAPID2 -expected-id $_BSTAPID3 -expected-id $_BSTAPID4 -expected-id $_BSTAPID5 -expected-id $_BSTAPID6 65 | 66 | set _TARGETNAME $_CHIPNAME.cpu 67 | target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME 68 | 69 | $_TARGETNAME configure -work-area-virt 0 -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 70 | 71 | set _FLASHNAME $_CHIPNAME.flash 72 | flash bank $_FLASHNAME stm32f1x 0x80000000 0x00020000 0 0 $_TARGETNAME 73 | -------------------------------------------------------------------------------- /stmlib/programming/jtag/stm32f4xx.cfg: -------------------------------------------------------------------------------- 1 | # Modified stm32f2xxx script to work with the st32f4 2 | # run something like this to flash your board 3 | # flash write_image erase demo.hex 0 ihex 4 | 5 | if { [info exists CHIPNAME] } { 6 | set _CHIPNAME $CHIPNAME 7 | } else { 8 | set _CHIPNAME stm32f4xxx 9 | } 10 | 11 | if { [info exists ENDIAN] } { 12 | set _ENDIAN $ENDIAN 13 | } else { 14 | set _ENDIAN little 15 | } 16 | 17 | # Work-area is a space in RAM used for flash programming 18 | # By default use 64kB 19 | if { [info exists WORKAREASIZE] } { 20 | set _WORKAREASIZE $WORKAREASIZE 21 | } else { 22 | set _WORKAREASIZE 0x10000 23 | } 24 | 25 | # JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz 26 | # 27 | # Since we may be running of an RC oscilator, we crank down the speed a 28 | # bit more to be on the safe side. Perhaps superstition, but if are 29 | # running off a crystal, we can run closer to the limit. Note 30 | # that there can be a pretty wide band where things are more or less stable. 31 | jtag_khz 2000 32 | 33 | jtag_nsrst_delay 100 34 | jtag_ntrst_delay 100 35 | 36 | reset_config trst_and_srst 37 | 38 | #jtag scan chain 39 | if { [info exists CPUTAPID ] } { 40 | set _CPUTAPID $CPUTAPID 41 | } else { 42 | # See STM Document RM0033 43 | # Section 32.6.3 - corresponds to Cortex-M3 r2p0 44 | set _CPUTAPID 0x4ba00477 45 | } 46 | jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID 47 | 48 | if { [info exists BSTAPID ] } { 49 | set _BSTAPID $BSTAPID 50 | } else { 51 | # See STM Document RM0033 52 | # Section 32.6.2 53 | # 54 | set _BSTAPID 0x06413041 55 | } 56 | jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID 57 | 58 | set _TARGETNAME $_CHIPNAME.cpu 59 | target create $_TARGETNAME cortex_m3 -endian $_ENDIAN -chain-position $_TARGETNAME 60 | 61 | $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 62 | 63 | set _FLASHNAME $_CHIPNAME.flash 64 | flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME 65 | -------------------------------------------------------------------------------- /stmlib/programming/merge_hex.awk: -------------------------------------------------------------------------------- 1 | BEGIN {} 2 | 3 | # add a record end marker 4 | END { print ":00000001FF" } 5 | 6 | # delete the record end marker 7 | /^:00000001FF/{ $0 = ""} 8 | 9 | # default action: output all non-blank lines 10 | { if ($0 != ""){ print } } -------------------------------------------------------------------------------- /stmlib/stmlib.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | 25 | #ifndef STMLIB_STMLIB_H_ 26 | #define STMLIB_STMLIB_H_ 27 | 28 | #include 29 | #include 30 | 31 | #ifndef NULL 32 | #define NULL 0 33 | #endif 34 | 35 | #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 36 | TypeName(const TypeName&); \ 37 | void operator=(const TypeName&) 38 | 39 | #define CLIP(x) if (x < -32767) x = -32767; if (x > 32767) x = 32767; 40 | 41 | #define CONSTRAIN(var, min, max) \ 42 | if (var < (min)) { \ 43 | var = (min); \ 44 | } else if (var > (max)) { \ 45 | var = (max); \ 46 | } 47 | 48 | #define STATIC_ASSERT(expression) StaticAssertImplementation<(expression)>() 49 | 50 | #ifndef TEST 51 | #define IN_RAM __attribute__ ((section (".ramtext"))) 52 | #else 53 | #define IN_RAM 54 | #endif // TEST 55 | 56 | #define UNROLL2(x) x; x; 57 | #define UNROLL4(x) x; x; x; x; 58 | #define UNROLL8(x) x; x; x; x; x; x; x; x; 59 | 60 | template 61 | inline void StaticAssertImplementation() { 62 | char static_assert_size_mismatch[b] = { 0 }; 63 | } 64 | 65 | namespace stmlib { 66 | 67 | typedef union { 68 | uint16_t value; 69 | uint8_t bytes[2]; 70 | } Word; 71 | 72 | typedef union { 73 | uint32_t value; 74 | uint16_t words[2]; 75 | uint8_t bytes[4]; 76 | } LongWord; 77 | 78 | 79 | template 80 | struct FourCC { 81 | static const uint32_t value = (((((d << 8) | c) << 8) | b) << 8) | a; 82 | }; 83 | 84 | } // namespace stmlib 85 | 86 | #endif // STMLIB_STMLIB_H_ 87 | -------------------------------------------------------------------------------- /stmlib/system/bootloader_utils.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Function for jumping from bootloader code to application code. 28 | 29 | #ifndef STM32F4XX 30 | 31 | #include "stmlib/system/bootloader_utils.h" 32 | 33 | #include 34 | 35 | namespace stmlib { 36 | 37 | #define u32 uint32_t 38 | #define vu32 volatile uint32_t 39 | 40 | #define SET_REG(addr,val) do { *(vu32*)(addr)=val; } while(0) 41 | #define GET_REG(addr) (*(vu32*)(addr)) 42 | 43 | #define RCC_CR RCC 44 | #define RCC_CFGR (RCC + 0x04) 45 | #define RCC_CIR (RCC + 0x08) 46 | #define RCC_AHBENR (RCC + 0x14) 47 | #define RCC_APB2ENR (RCC + 0x18) 48 | #define RCC_APB1ENR (RCC + 0x1C) 49 | 50 | #define SCS 0xE000E000 51 | #define STK (SCS+0x10) 52 | #define STK_CTRL (STK+0x00) 53 | #define RCC_CR RCC 54 | 55 | typedef struct { 56 | vu32 ISER[2]; 57 | u32 RESERVED0[30]; 58 | vu32 ICER[2]; 59 | u32 RSERVED1[30]; 60 | vu32 ISPR[2]; 61 | u32 RESERVED2[30]; 62 | vu32 ICPR[2]; 63 | u32 RESERVED3[30]; 64 | vu32 IABR[2]; 65 | u32 RESERVED4[62]; 66 | vu32 IPR[15]; 67 | } NVIC_TypeDef; 68 | 69 | void Uninitialize() { 70 | // Stop NVIC. 71 | NVIC_TypeDef *rNVIC = (NVIC_TypeDef *) NVIC_BASE; 72 | rNVIC->ICER[0] = 0xFFFFFFFF; 73 | rNVIC->ICER[1] = 0xFFFFFFFF; 74 | rNVIC->ICPR[0] = 0xFFFFFFFF; 75 | rNVIC->ICPR[1] = 0xFFFFFFFF; 76 | SET_REG(STK_CTRL, 0x04); 77 | 78 | // System reset. 79 | SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00000001); 80 | SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xF8FF0000); 81 | SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFEF6FFFF); 82 | SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFFFBFFFF); 83 | SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xFF80FFFF); 84 | SET_REG(RCC_CIR, 0x00000000); 85 | } 86 | 87 | typedef void (*EntryPoint)(void); 88 | 89 | void JumpTo(uint32_t address) { 90 | uint32_t application_address = *(__IO uint32_t*)(address + 4); 91 | EntryPoint application = (EntryPoint)(application_address); 92 | __set_MSP(*(__IO uint32_t*)address); 93 | application(); 94 | } 95 | 96 | } // namespace stmlib 97 | 98 | #endif // #ifndef STM32F4XX 99 | -------------------------------------------------------------------------------- /stmlib/system/bootloader_utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Function for jumping from bootloader code to application code. 28 | 29 | #ifndef STMLIB_SYSTEM_BOOTLOADER_UTILS_H_ 30 | #define STMLIB_SYSTEM_BOOTLOADER_UTILS_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | namespace stmlib { 35 | 36 | void Uninitialize(); 37 | void JumpTo(uint32_t address); 38 | 39 | } // namespace stmlib 40 | 41 | #endif // STMLIB_SYSTEM_BOOTLOADER_UTILS_H_ 42 | -------------------------------------------------------------------------------- /stmlib/system/flash_programming.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Helper functions for flash programming. 28 | 29 | #ifndef STMLIB_SYSTEM_FLASH_PROGRAMMING_H_ 30 | #define STMLIB_SYSTEM_FLASH_PROGRAMMING_H_ 31 | 32 | #if defined (STM32F10X_LD) || defined (STM32F10X_MD) 33 | #define PAGE_SIZE (uint16_t)0x400 /* Page size = 1KByte */ 34 | #elif defined (STM32F10X_HD) || defined (STM32F10X_CL) 35 | #define PAGE_SIZE (uint16_t)0x800 /* Page size = 2KByte */ 36 | #endif 37 | 38 | #endif // STMLIB_SYSTEM_FLASH_PROGRAMMING_H_ 39 | -------------------------------------------------------------------------------- /stmlib/system/system_clock.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // System time. 28 | 29 | #include "stmlib/system/system_clock.h" 30 | 31 | namespace stmlib { 32 | 33 | /* extern */ 34 | SystemClock system_clock; 35 | 36 | } // namespace stmlib 37 | -------------------------------------------------------------------------------- /stmlib/system/system_clock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // System time. 28 | 29 | #ifndef STMLIB_SYSTEM_SYSTEM_CLOCK_H_ 30 | #define STMLIB_SYSTEM_SYSTEM_CLOCK_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | namespace stmlib { 35 | 36 | class SystemClock { 37 | public: 38 | SystemClock() { } 39 | ~SystemClock() { } 40 | 41 | inline void Init() { count_ = 0; } 42 | inline void Tick() { ++count_; } 43 | inline volatile uint32_t milliseconds() const { return count_; } 44 | inline void Delay(uint32_t ms) { 45 | uint32_t target = milliseconds() + ms; 46 | while (milliseconds() <= target); 47 | } 48 | 49 | private: 50 | volatile uint32_t count_; 51 | 52 | DISALLOW_COPY_AND_ASSIGN(SystemClock); 53 | }; 54 | 55 | extern SystemClock system_clock; 56 | 57 | } // namespace stmlib 58 | 59 | #endif // STMLIB_SYSTEM_SYSTEM_CLOCK_H_ 60 | -------------------------------------------------------------------------------- /stmlib/system/uid.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Helper functions for using the last page of flash for non-volatile storage. 28 | 29 | #ifndef STMLIB_SYSTEM_UID_H_ 30 | #define STMLIB_SYSTEM_UID_H_ 31 | 32 | #include 33 | 34 | #include "stmlib/stmlib.h" 35 | 36 | namespace stmlib { 37 | 38 | uint32_t GetUniqueId(uint8_t word) { 39 | uint32_t* base_address = (uint32_t*)(0x1ffff7e8); 40 | return base_address[word]; 41 | } 42 | 43 | }; // namespace stmlib 44 | 45 | #endif // STMLIB_SYSTEM_UID_H_ 46 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/CMSIS/CM3_f10x/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.1.2 6 | * @date 09/28/2009 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * 10 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 12 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 13 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 14 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 15 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 16 | * 17 | *

© COPYRIGHT 2009 STMicroelectronics

18 | ****************************************************************************** 19 | */ 20 | 21 | /** @addtogroup CMSIS 22 | * @{ 23 | */ 24 | 25 | /** @addtogroup stm32f10x_system 26 | * @{ 27 | */ 28 | 29 | /** 30 | * @brief Define to prevent recursive inclusion 31 | */ 32 | #ifndef __SYSTEM_STM32F10X_H 33 | #define __SYSTEM_STM32F10X_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /** @addtogroup STM32F10x_System_Includes 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @} 45 | */ 46 | 47 | 48 | /** @addtogroup STM32F10x_System_Exported_types 49 | * @{ 50 | */ 51 | 52 | extern const uint32_t SystemFrequency; /*!< System Clock Frequency (Core Clock) */ 53 | extern const uint32_t SystemFrequency_SysClk; /*!< System clock */ 54 | extern const uint32_t SystemFrequency_AHBClk; /*!< AHB System bus speed */ 55 | extern const uint32_t SystemFrequency_APB1Clk; /*!< APB Peripheral Bus 1 (low) speed */ 56 | extern const uint32_t SystemFrequency_APB2Clk; /*!< APB Peripheral Bus 2 (high) speed */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @addtogroup STM32F10x_System_Exported_Constants 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @addtogroup STM32F10x_System_Exported_Macros 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @addtogroup STM32F10x_System_Exported_Functions 79 | * @{ 80 | */ 81 | 82 | extern void SystemInit(void); 83 | /** 84 | * @} 85 | */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /*__SYSTEM_STM32F10X_H */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** 98 | * @} 99 | */ 100 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/CMSIS/CM3_f4xx/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 11. November 2010 5 | * $Revision: V1.0.2 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Version 1.0.2 2010/11/11 15 | * Documentation updated. 16 | * 17 | * Version 1.0.1 2010/10/05 18 | * Production release and review comments incorporated. 19 | * 20 | * Version 1.0.0 2010/09/20 21 | * Production release and review comments incorporated. 22 | * -------------------------------------------------------------------- */ 23 | 24 | #ifndef _ARM_COMMON_TABLES_H 25 | #define _ARM_COMMON_TABLES_H 26 | 27 | #include "arm_math.h" 28 | 29 | extern uint16_t armBitRevTable[256]; 30 | extern q15_t armRecipTableQ15[64]; 31 | extern q31_t armRecipTableQ31[64]; 32 | extern const q31_t realCoefAQ31[1024]; 33 | extern const q31_t realCoefBQ31[1024]; 34 | 35 | #endif /* ARM_COMMON_TABLES_H */ 36 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/CMSIS/CM3_f4xx/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/CMSIS/CM3_f4xx/stm32f4xx.h -------------------------------------------------------------------------------- /stmlib/third_party/STM/CMSIS/CM3_f4xx/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2012 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 stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.1.2 6 | * @date 09/28/2009 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CRC_H 24 | #define __STM32F10x_CRC_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /** @addtogroup STM32F10x_StdPeriph_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup CRC 38 | * @{ 39 | */ 40 | 41 | /** @defgroup CRC_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup CRC_Exported_Constants 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | /** @defgroup CRC_Exported_Macros 58 | * @{ 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup CRC_Exported_Functions 66 | * @{ 67 | */ 68 | 69 | void CRC_ResetDR(void); 70 | uint32_t CRC_CalcCRC(uint32_t Data); 71 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 72 | uint32_t CRC_GetCRC(void); 73 | void CRC_SetIDRegister(uint8_t IDValue); 74 | uint8_t CRC_GetIDRegister(void); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __STM32F10x_CRC_H */ 81 | /** 82 | * @} 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 94 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.1.2 6 | * @date 09/28/2009 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_DBGMCU_H 24 | #define __STM32F10x_DBGMCU_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /** @addtogroup STM32F10x_StdPeriph_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup DBGMCU 38 | * @{ 39 | */ 40 | 41 | /** @defgroup DBGMCU_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup DBGMCU_Exported_Constants 50 | * @{ 51 | */ 52 | 53 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 54 | #define DBGMCU_STOP ((uint32_t)0x00000002) 55 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 56 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 57 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 58 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 59 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 60 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 61 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 62 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 63 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 64 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 65 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 66 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 67 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 68 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 69 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 70 | 71 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0xFFC000F8) == 0x00) && ((PERIPH) != 0x00)) 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup DBGMCU_Exported_Macros 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup DBGMCU_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | uint32_t DBGMCU_GetREVID(void); 89 | uint32_t DBGMCU_GetDEVID(void); 90 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* __STM32F10x_DBGMCU_H */ 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/inc/stm32f10x_fsmc.h -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.1.2 6 | * @date 09/28/2009 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @copy 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2009 STMicroelectronics

20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_WWDG_H 24 | #define __STM32F10x_WWDG_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | 33 | /** @addtogroup STM32F10x_StdPeriph_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup WWDG 38 | * @{ 39 | */ 40 | 41 | /** @defgroup WWDG_Exported_Types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** @defgroup WWDG_Exported_Constants 50 | * @{ 51 | */ 52 | 53 | /** @defgroup WWDG_Prescaler 54 | * @{ 55 | */ 56 | 57 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 58 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 59 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 60 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 61 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 62 | ((PRESCALER) == WWDG_Prescaler_2) || \ 63 | ((PRESCALER) == WWDG_Prescaler_4) || \ 64 | ((PRESCALER) == WWDG_Prescaler_8)) 65 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 66 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup WWDG_Exported_Macros 77 | * @{ 78 | */ 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup WWDG_Exported_Functions 84 | * @{ 85 | */ 86 | 87 | void WWDG_DeInit(void); 88 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 89 | void WWDG_SetWindowValue(uint8_t WindowValue); 90 | void WWDG_EnableIT(void); 91 | void WWDG_SetCounter(uint8_t Counter); 92 | void WWDG_Enable(uint8_t Counter); 93 | FlagStatus WWDG_GetFlagStatus(void); 94 | void WWDG_ClearFlag(void); 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif /* __STM32F10x_WWDG_H */ 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | /** 107 | * @} 108 | */ 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 115 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_adc.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_dma.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_fsmc.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_rtc.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_sdio.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_tim.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_tim.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.0.2 6 | * @date 05-March-2012 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * 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 __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_flash.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/third_party/STM/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/otgd_fs_int.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : otgd_fs_int.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Endpoint interrupt's service routines prototypes. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_INT_H 18 | #define __USB_INT_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | 26 | #ifdef STM32F10X_CL 27 | 28 | /* Interrupt Handlers functions */ 29 | uint32_t OTGD_FS_Handle_ModeMismatch_ISR(void); 30 | uint32_t OTGD_FS_Handle_Sof_ISR(void); 31 | uint32_t OTGD_FS_Handle_RxStatusQueueLevel_ISR(void); 32 | uint32_t OTGD_FS_Handle_NPTxFE_ISR(void); 33 | uint32_t OTGD_FS_Handle_GInNakEff_ISR(void); 34 | uint32_t OTGD_FS_Handle_GOutNakEff_ISR(void); 35 | uint32_t OTGD_FS_Handle_EarlySuspend_ISR(void); 36 | uint32_t OTGD_FS_Handle_USBSuspend_ISR(void); 37 | uint32_t OTGD_FS_Handle_UsbReset_ISR(void); 38 | uint32_t OTGD_FS_Handle_EnumDone_ISR(void); 39 | uint32_t OTGD_FS_Handle_IsoOutDrop_ISR(void); 40 | uint32_t OTGD_FS_Handle_EOPF_ISR(void); 41 | uint32_t OTGD_FS_Handle_EPMismatch_ISR(void); 42 | uint32_t OTGD_FS_Handle_InEP_ISR(void); 43 | uint32_t OTGD_FS_Handle_OutEP_ISR(void); 44 | uint32_t OTGD_FS_Handle_IncomplIsoIn_ISR(void); 45 | uint32_t OTGD_FS_Handle_IncomplIsoOut_ISR(void); 46 | uint32_t OTGD_FS_Handle_Wakeup_ISR(void); 47 | 48 | #endif /* STM32F10X_CL */ 49 | 50 | /* External variables --------------------------------------------------------*/ 51 | 52 | #endif /* __USB_INT_H */ 53 | 54 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_def.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_def.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Definitions related to USB Core 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_DEF_H 18 | #define __USB_DEF_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | typedef enum _RECIPIENT_TYPE 23 | { 24 | DEVICE_RECIPIENT, /* Recipient device */ 25 | INTERFACE_RECIPIENT, /* Recipient interface */ 26 | ENDPOINT_RECIPIENT, /* Recipient endpoint */ 27 | OTHER_RECIPIENT 28 | } RECIPIENT_TYPE; 29 | 30 | 31 | typedef enum _STANDARD_REQUESTS 32 | { 33 | GET_STATUS = 0, 34 | CLEAR_FEATURE, 35 | RESERVED1, 36 | SET_FEATURE, 37 | RESERVED2, 38 | SET_ADDRESS, 39 | GET_DESCRIPTOR, 40 | SET_DESCRIPTOR, 41 | GET_CONFIGURATION, 42 | SET_CONFIGURATION, 43 | GET_INTERFACE, 44 | SET_INTERFACE, 45 | TOTAL_sREQUEST, /* Total number of Standard request */ 46 | SYNCH_FRAME = 12 47 | } STANDARD_REQUESTS; 48 | 49 | /* Definition of "USBwValue" */ 50 | typedef enum _DESCRIPTOR_TYPE 51 | { 52 | DEVICE_DESCRIPTOR = 1, 53 | CONFIG_DESCRIPTOR, 54 | STRING_DESCRIPTOR, 55 | INTERFACE_DESCRIPTOR, 56 | ENDPOINT_DESCRIPTOR 57 | } DESCRIPTOR_TYPE; 58 | 59 | /* Feature selector of a SET_FEATURE or CLEAR_FEATURE */ 60 | typedef enum _FEATURE_SELECTOR 61 | { 62 | ENDPOINT_STALL, 63 | DEVICE_REMOTE_WAKEUP 64 | } FEATURE_SELECTOR; 65 | 66 | /* Exported constants --------------------------------------------------------*/ 67 | /* Definition of "USBbmRequestType" */ 68 | #define REQUEST_TYPE 0x60 /* Mask to get request type */ 69 | #define STANDARD_REQUEST 0x00 /* Standard request */ 70 | #define CLASS_REQUEST 0x20 /* Class request */ 71 | #define VENDOR_REQUEST 0x40 /* Vendor request */ 72 | 73 | #define RECIPIENT 0x1F /* Mask to get recipient */ 74 | 75 | /* Exported macro ------------------------------------------------------------*/ 76 | /* Exported functions ------------------------------------------------------- */ 77 | 78 | #endif /* __USB_DEF_H */ 79 | 80 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 81 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_init.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_init.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Initialization routines & global variables 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_INIT_H 18 | #define __USB_INIT_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | void USB_Init(void); 26 | 27 | /* External variables --------------------------------------------------------*/ 28 | /* The number of current endpoint, it will be used to specify an endpoint */ 29 | extern uint8_t EPindex; 30 | /* The number of current device, it is an index to the Device_Table */ 31 | /*extern uint8_t Device_no; */ 32 | /* Points to the DEVICE_INFO structure of current device */ 33 | /* The purpose of this register is to speed up the execution */ 34 | extern DEVICE_INFO* pInformation; 35 | /* Points to the DEVICE_PROP structure of current device */ 36 | /* The purpose of this register is to speed up the execution */ 37 | extern DEVICE_PROP* pProperty; 38 | /* Temporary save the state of Rx & Tx status. */ 39 | /* Whenever the Rx or Tx state is changed, its value is saved */ 40 | /* in this variable first and will be set to the EPRB or EPRA */ 41 | /* at the end of interrupt process */ 42 | extern USER_STANDARD_REQUESTS *pUser_Standard_Requests; 43 | 44 | extern uint16_t SaveState ; 45 | extern uint16_t wInterrupt_Mask; 46 | 47 | #endif /* __USB_INIT_H */ 48 | 49 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_int.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_int.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Endpoint CTR (Low and High) interrupt's service routines 7 | * prototypes 8 | ******************************************************************************** 9 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 10 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 11 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 12 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 13 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 14 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 15 | *******************************************************************************/ 16 | 17 | /* Define to prevent recursive inclusion -------------------------------------*/ 18 | #ifndef __USB_INT_H 19 | #define __USB_INT_H 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | /* Exported types ------------------------------------------------------------*/ 23 | /* Exported constants --------------------------------------------------------*/ 24 | /* Exported macro ------------------------------------------------------------*/ 25 | /* Exported functions ------------------------------------------------------- */ 26 | void CTR_LP(void); 27 | void CTR_HP(void); 28 | 29 | /* External variables --------------------------------------------------------*/ 30 | 31 | #endif /* __USB_INT_H */ 32 | 33 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 34 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_lib.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_lib.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : USB library include files 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_LIB_H 18 | #define __USB_LIB_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "stm32f10x.h" 22 | #include "usb_type.h" 23 | #include "usb_regs.h" 24 | #include "usb_def.h" 25 | #include "usb_core.h" 26 | #include "usb_init.h" 27 | #ifndef STM32F10X_CL 28 | #include "usb_mem.h" 29 | #include "usb_int.h" 30 | #endif /* STM32F10X_CL */ 31 | 32 | #include "usb_sil.h" 33 | 34 | #ifdef STM32F10X_CL 35 | #include "otgd_fs_cal.h" 36 | #include "otgd_fs_pcd.h" 37 | #include "otgd_fs_dev.h" 38 | #include "otgd_fs_int.h" 39 | #endif /* STM32F10X_CL */ 40 | 41 | 42 | /* Exported types ------------------------------------------------------------*/ 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported functions ------------------------------------------------------- */ 46 | /* External variables --------------------------------------------------------*/ 47 | 48 | #endif /* __USB_LIB_H */ 49 | 50 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 51 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_mem.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_mem.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Utility prototypes functions for memory/PMA transfers 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_MEM_H 18 | #define __USB_MEM_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 26 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); 27 | 28 | /* External variables --------------------------------------------------------*/ 29 | 30 | #endif /*__USB_MEM_H*/ 31 | 32 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 33 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_sil.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_sil.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Simplified Interface Layer function prototypes. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_SIL_H 18 | #define __USB_SIL_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Exported types ------------------------------------------------------------*/ 22 | /* Exported constants --------------------------------------------------------*/ 23 | /* Exported macro ------------------------------------------------------------*/ 24 | /* Exported functions ------------------------------------------------------- */ 25 | 26 | uint32_t USB_SIL_Init(void); 27 | uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize); 28 | uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer); 29 | 30 | /* External variables --------------------------------------------------------*/ 31 | 32 | #endif /* __USB_SIL_H */ 33 | 34 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 35 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/inc/usb_type.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_type.h 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Type definitions used by the USB Library 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __USB_TYPE_H 18 | #define __USB_TYPE_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usb_conf.h" 22 | 23 | /* Exported types ------------------------------------------------------------*/ 24 | /* Exported constants --------------------------------------------------------*/ 25 | #ifndef NULL 26 | #define NULL ((void *)0) 27 | #endif 28 | 29 | #ifndef __STM32F10x_H 30 | 31 | typedef signed long s32; 32 | typedef signed short s16; 33 | typedef signed char s8; 34 | 35 | typedef volatile signed long vs32; 36 | typedef volatile signed short vs16; 37 | typedef volatile signed char vs8; 38 | 39 | typedef unsigned long u32; 40 | typedef unsigned short u16; 41 | typedef unsigned char u8; 42 | 43 | typedef unsigned long const uc32; /* Read Only */ 44 | typedef unsigned short const uc16; /* Read Only */ 45 | typedef unsigned char const uc8; /* Read Only */ 46 | 47 | typedef volatile unsigned long vu32; 48 | typedef volatile unsigned short vu16; 49 | typedef volatile unsigned char vu8; 50 | 51 | typedef volatile unsigned long const vuc32; /* Read Only */ 52 | typedef volatile unsigned short const vuc16; /* Read Only */ 53 | typedef volatile unsigned char const vuc8; /* Read Only */ 54 | 55 | 56 | typedef enum 57 | { 58 | FALSE = 0, TRUE = !FALSE 59 | } 60 | bool; 61 | 62 | typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus; 63 | 64 | typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState; 65 | 66 | typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus; 67 | #endif 68 | /* Exported macro ------------------------------------------------------------*/ 69 | /* Exported functions ------------------------------------------------------- */ 70 | /* External variables --------------------------------------------------------*/ 71 | 72 | #endif /* __USB_TYPE_H */ 73 | 74 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/src/usb_init.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_init.c 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Initialization routines & global variables 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Includes ------------------------------------------------------------------*/ 17 | #include "usb_lib.h" 18 | 19 | /* Private typedef -----------------------------------------------------------*/ 20 | /* Private define ------------------------------------------------------------*/ 21 | /* Private macro -------------------------------------------------------------*/ 22 | /* Private variables ---------------------------------------------------------*/ 23 | /* The number of current endpoint, it will be used to specify an endpoint */ 24 | uint8_t EPindex; 25 | /* The number of current device, it is an index to the Device_Table */ 26 | /* uint8_t Device_no; */ 27 | /* Points to the DEVICE_INFO structure of current device */ 28 | /* The purpose of this register is to speed up the execution */ 29 | DEVICE_INFO *pInformation; 30 | /* Points to the DEVICE_PROP structure of current device */ 31 | /* The purpose of this register is to speed up the execution */ 32 | DEVICE_PROP *pProperty; 33 | /* Temporary save the state of Rx & Tx status. */ 34 | /* Whenever the Rx or Tx state is changed, its value is saved */ 35 | /* in this variable first and will be set to the EPRB or EPRA */ 36 | /* at the end of interrupt process */ 37 | uint16_t SaveState ; 38 | uint16_t wInterrupt_Mask; 39 | DEVICE_INFO Device_Info; 40 | USER_STANDARD_REQUESTS *pUser_Standard_Requests; 41 | 42 | /* Extern variables ----------------------------------------------------------*/ 43 | /* Private function prototypes -----------------------------------------------*/ 44 | /* Private functions ---------------------------------------------------------*/ 45 | 46 | /******************************************************************************* 47 | * Function Name : USB_Init 48 | * Description : USB system initialization 49 | * Input : None. 50 | * Output : None. 51 | * Return : None. 52 | *******************************************************************************/ 53 | void USB_Init(void) 54 | { 55 | pInformation = &Device_Info; 56 | pInformation->ControlState = 2; 57 | pProperty = &Device_Property; 58 | pUser_Standard_Requests = &User_Standard_Requests; 59 | /* Initialize devices one by one */ 60 | pProperty->Init(); 61 | } 62 | 63 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 64 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/STM32_USB-FS-Device_Driver/src/usb_mem.c: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : usb_mem.c 3 | * Author : MCD Application Team 4 | * Version : V3.1.0 5 | * Date : 10/30/2009 6 | * Description : Utility functions for memory transfers to/from PMA 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | #ifndef STM32F10X_CL 16 | 17 | /* Includes ------------------------------------------------------------------*/ 18 | #include "usb_lib.h" 19 | 20 | /* Private typedef -----------------------------------------------------------*/ 21 | /* Private define ------------------------------------------------------------*/ 22 | /* Private macro -------------------------------------------------------------*/ 23 | /* Private variables ---------------------------------------------------------*/ 24 | /* Extern variables ----------------------------------------------------------*/ 25 | /* Private function prototypes -----------------------------------------------*/ 26 | /* Private functions ---------------------------------------------------------*/ 27 | /******************************************************************************* 28 | * Function Name : UserToPMABufferCopy 29 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 30 | * Input : - pbUsrBuf: pointer to user memory area. 31 | * - wPMABufAddr: address into PMA. 32 | * - wNBytes: no. of bytes to be copied. 33 | * Output : None. 34 | * Return : None . 35 | *******************************************************************************/ 36 | void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 37 | { 38 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 39 | uint32_t i, temp1, temp2; 40 | uint16_t *pdwVal; 41 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr); 42 | for (i = n; i != 0; i--) 43 | { 44 | temp1 = (uint16_t) * pbUsrBuf; 45 | pbUsrBuf++; 46 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; 47 | *pdwVal++ = temp2; 48 | pdwVal++; 49 | pbUsrBuf++; 50 | } 51 | } 52 | /******************************************************************************* 53 | * Function Name : PMAToUserBufferCopy 54 | * Description : Copy a buffer from user memory area to packet memory area (PMA) 55 | * Input : - pbUsrBuf = pointer to user memory area. 56 | * - wPMABufAddr = address into PMA. 57 | * - wNBytes = no. of bytes to be copied. 58 | * Output : None. 59 | * Return : None. 60 | *******************************************************************************/ 61 | void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) 62 | { 63 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ 64 | uint32_t i; 65 | uint32_t *pdwVal; 66 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr); 67 | for (i = n; i != 0; i--) 68 | { 69 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; 70 | pbUsrBuf++; 71 | } 72 | } 73 | 74 | #endif /* STM32F10X_CL */ 75 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /stmlib/third_party/STM/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /******************** (C) COPYRIGHT 2009 STMicroelectronics ******************** 2 | * File Name : stm32f10x_conf.h 3 | * Author : MCD Application Team 4 | * Version : V3.0.0 5 | * Date : 04/06/2009 6 | * Description : Library configuration file. 7 | ******************************************************************************** 8 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 9 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 10 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 11 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 12 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 13 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 14 | *******************************************************************************/ 15 | 16 | /* Define to prevent recursive inclusion -------------------------------------*/ 17 | #ifndef __STM32F10x_CONF_H 18 | #define __STM32F10x_CONF_H 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | /* Uncomment the line below to enable peripheral header file inclusion */ 22 | #include "stm32f10x_adc.h" 23 | #include "stm32f10x_bkp.h" 24 | #include "stm32f10x_can.h" 25 | #include "stm32f10x_crc.h" 26 | #include "stm32f10x_dac.h" 27 | #include "stm32f10x_dbgmcu.h" 28 | #include "stm32f10x_dma.h" 29 | #include "stm32f10x_exti.h" 30 | #include "stm32f10x_flash.h" 31 | #include "stm32f10x_fsmc.h" 32 | #include "stm32f10x_gpio.h" 33 | #include "stm32f10x_i2c.h" 34 | #include "stm32f10x_iwdg.h" 35 | #include "stm32f10x_pwr.h" 36 | #include "stm32f10x_rcc.h" 37 | #include "stm32f10x_rtc.h" 38 | #include "stm32f10x_sdio.h" 39 | #include "stm32f10x_spi.h" 40 | #include "stm32f10x_tim.h" 41 | #include "stm32f10x_usart.h" 42 | #include "stm32f10x_wwdg.h" 43 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 44 | 45 | /* Exported types ------------------------------------------------------------*/ 46 | /* Exported constants --------------------------------------------------------*/ 47 | /* Uncomment the line below to expanse the "assert_param" macro in the 48 | Standard Peripheral Library drivers code */ 49 | /* #define USE_FULL_ASSERT 1 */ 50 | 51 | /* Exported macro ------------------------------------------------------------*/ 52 | #ifdef USE_FULL_ASSERT 53 | 54 | /******************************************************************************* 55 | * Macro Name : assert_param 56 | * Description : The assert_param macro is used for function's parameters check. 57 | * Input : - expr: If expr is false, it calls assert_failed function 58 | * which reports the name of the source file and the source 59 | * line number of the call that failed. 60 | * If expr is true, it returns no value. 61 | * Return : None 62 | *******************************************************************************/ 63 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 64 | /* Exported functions ------------------------------------------------------- */ 65 | void assert_failed(uint8_t* file, uint32_t line); 66 | #else 67 | #define assert_param(expr) ((void)0) 68 | #endif /* USE_FULL_ASSERT */ 69 | 70 | #endif /* __STM32F10x_CONF_H */ 71 | 72 | /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /stmlib/tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modlfo/teensy-braids/b9be166187fa74ccd26861d0c10048162261a3e2/stmlib/tools/__init__.py -------------------------------------------------------------------------------- /stmlib/ui/event_queue.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // This program is free software: you can redistribute it and/or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 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 | // You should have received a copy of the GNU General Public License 14 | // along with this program. If not, see . 15 | // 16 | // ----------------------------------------------------------------------------- 17 | // 18 | // Event queue. 19 | 20 | #ifndef STMLIB_UI_EVENT_QUEUE_H_ 21 | #define STMLIB_UI_EVENT_QUEUE_H_ 22 | 23 | #include "stmlib/stmlib.h" 24 | #include "stmlib/utils/ring_buffer.h" 25 | #include "stmlib/system/system_clock.h" 26 | 27 | namespace stmlib { 28 | 29 | enum ControlType { 30 | CONTROL_POT = 0, 31 | CONTROL_ENCODER = 1, 32 | CONTROL_ENCODER_CLICK = 2, 33 | CONTROL_ENCODER_LONG_CLICK = 3, 34 | CONTROL_SWITCH = 4, 35 | CONTROL_SWITCH_HOLD = 5, 36 | CONTROL_REFRESH = 0xff 37 | }; 38 | 39 | struct Event { 40 | ControlType control_type; 41 | uint16_t control_id; 42 | int32_t data; 43 | }; 44 | 45 | template 46 | class EventQueue { 47 | public: 48 | EventQueue() { } 49 | 50 | void Init() { 51 | events_.Init(); 52 | } 53 | 54 | void Flush() { 55 | events_.Flush(); 56 | }; 57 | 58 | void AddEvent(ControlType control_type, uint16_t id, int32_t data) { 59 | Event e; 60 | e.control_type = control_type; 61 | e.control_id = id; 62 | e.data = data; 63 | events_.Overwrite(e); 64 | Touch(); 65 | } 66 | 67 | void Touch() { 68 | last_event_time_ = system_clock.milliseconds(); 69 | } 70 | 71 | size_t available() { 72 | return events_.readable(); 73 | } 74 | 75 | uint32_t idle_time() { 76 | uint32_t now = system_clock.milliseconds(); 77 | return now - last_event_time_; 78 | } 79 | 80 | Event PullEvent() { 81 | return events_.ImmediateRead(); 82 | } 83 | 84 | private: 85 | uint32_t last_event_time_; 86 | RingBuffer events_; 87 | }; 88 | 89 | } // namespace stmlib 90 | 91 | #endif // STMLIB_UI_EVENT_QUEUE_H_ 92 | -------------------------------------------------------------------------------- /stmlib/utils/murmurhash3.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash3 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | //----------------------------------------------------------------------------- 5 | 6 | uint32_t rotl32 ( uint32_t x, int8_t r ) 7 | { 8 | return (x << r) | (x >> (32 - r)); 9 | } 10 | 11 | uint32_t fmix32 ( uint32_t h ) 12 | { 13 | h ^= h >> 16; 14 | h *= 0x85ebca6b; 15 | h ^= h >> 13; 16 | h *= 0xc2b2ae35; 17 | h ^= h >> 16; 18 | 19 | return h; 20 | } 21 | 22 | void MurmurHash3_x86_32 ( const void * key, int len, 23 | uint32_t seed, void * out ) 24 | { 25 | const uint8_t * data = (const uint8_t*)key; 26 | const int nblocks = len / 4; 27 | 28 | uint32_t h1 = seed; 29 | 30 | const uint32_t c1 = 0xcc9e2d51; 31 | const uint32_t c2 = 0x1b873593; 32 | 33 | //---------- 34 | // body 35 | 36 | const uint32_t * blocks = (const uint32_t *)(data + nblocks*4); 37 | 38 | for(int i = -nblocks; i; i++) 39 | { 40 | uint32_t k1 = blocks[i]; 41 | 42 | k1 *= c1; 43 | k1 = rotl32(k1,15); 44 | k1 *= c2; 45 | 46 | h1 ^= k1; 47 | h1 = rotl32(h1,13); 48 | h1 = h1*5+0xe6546b64; 49 | } 50 | 51 | //---------- 52 | // tail 53 | 54 | const uint8_t * tail = (const uint8_t*)(data + nblocks*4); 55 | 56 | uint32_t k1 = 0; 57 | 58 | switch(len & 3) 59 | { 60 | case 3: k1 ^= tail[2] << 16; 61 | case 2: k1 ^= tail[1] << 8; 62 | case 1: k1 ^= tail[0]; 63 | k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1; 64 | }; 65 | 66 | //---------- 67 | // finalization 68 | 69 | h1 ^= len; 70 | 71 | h1 = fmix32(h1); 72 | 73 | *(uint32_t*)out = h1; 74 | } 75 | -------------------------------------------------------------------------------- /stmlib/utils/random.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Random number generator. 28 | 29 | #include "stmlib/utils/random.h" 30 | 31 | namespace stmlib { 32 | 33 | /* static */ 34 | uint32_t Random::rng_state_ = 0x21; 35 | 36 | } // namespace stmlib 37 | -------------------------------------------------------------------------------- /stmlib/utils/random.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Fast 16-bit pseudo random number generator. 28 | 29 | #ifndef STMLIB_UTILS_RANDOM_H_ 30 | #define STMLIB_UTILS_RANDOM_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | namespace stmlib { 35 | 36 | class Random { 37 | public: 38 | static inline uint32_t state() { return rng_state_; } 39 | 40 | static inline void Seed(uint16_t seed) { 41 | rng_state_ = seed; 42 | } 43 | 44 | static inline uint32_t GetWord() { 45 | rng_state_ = rng_state_ * 1664525L + 1013904223L; 46 | return state(); 47 | } 48 | 49 | static inline int16_t GetSample() { 50 | return static_cast(GetWord() >> 16); 51 | } 52 | 53 | private: 54 | static uint32_t rng_state_; 55 | 56 | DISALLOW_COPY_AND_ASSIGN(Random); 57 | }; 58 | 59 | } // namespace stmlib 60 | 61 | #endif // STMLIB_UTILS_RANDOM_H_ 62 | -------------------------------------------------------------------------------- /stmlib/utils/stream_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Olivier Gillet. 2 | // 3 | // Author: Olivier Gillet (ol.gillet@gmail.com) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | // 23 | // See http://creativecommons.org/licenses/MIT/ for more information. 24 | // 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Stream buffer for serialization. 28 | 29 | #ifndef STMLIB_UTILS_STREAM_BUFFER_H_ 30 | #define STMLIB_UTILS_STREAM_BUFFER_H_ 31 | 32 | #include "stmlib/stmlib.h" 33 | 34 | #include 35 | #include 36 | 37 | namespace stmlib { 38 | 39 | template 40 | class StreamBuffer { 41 | public: 42 | StreamBuffer() { Clear(); } 43 | 44 | void Clear() { 45 | ptr_ = 0; 46 | std::fill(&buffer_[0], &buffer_[buffer_size], 0); 47 | } 48 | 49 | inline size_t position() const { 50 | return ptr_; 51 | } 52 | 53 | inline const uint8_t* bytes() const { 54 | return buffer_; 55 | } 56 | 57 | inline uint8_t* mutable_bytes() { 58 | return buffer_; 59 | } 60 | 61 | void Write(const void* data, size_t size) { 62 | if (ptr_ + size > buffer_size) { 63 | return; 64 | } 65 | memcpy(&buffer_[ptr_], data, size); 66 | ptr_ += size; 67 | } 68 | 69 | template 70 | void Write(const T& value) { 71 | Write(&value, sizeof(T)); 72 | } 73 | 74 | template 75 | void Read(T* value) { 76 | if (ptr_ + sizeof(T) > buffer_size) { 77 | return; 78 | } 79 | memcpy((void*)value, &buffer_[ptr_], sizeof(T)); 80 | ptr_ += sizeof(T); 81 | } 82 | 83 | inline void Seek(size_t position) { 84 | ptr_ = position; 85 | } 86 | 87 | inline void Rewind() { Seek(0); } 88 | 89 | private: 90 | uint8_t buffer_[buffer_size]; 91 | size_t ptr_; 92 | 93 | DISALLOW_COPY_AND_ASSIGN(StreamBuffer); 94 | }; 95 | 96 | } // namespace stmlib 97 | 98 | #endif // STMLIB_UTILS_STREAM_BUFFER_H_ 99 | -------------------------------------------------------------------------------- /usb_inst.cpp: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "WProgram.h" 32 | #include "usb_desc.h" 33 | 34 | #if F_CPU >= 20000000 35 | 36 | #ifdef CDC_DATA_INTERFACE 37 | #ifdef CDC_STATUS_INTERFACE 38 | usb_serial_class Serial; 39 | #endif 40 | #endif 41 | 42 | #ifdef MIDI_INTERFACE 43 | usb_midi_class usbMIDI; 44 | #endif 45 | 46 | #ifdef KEYBOARD_INTERFACE 47 | usb_keyboard_class Keyboard; 48 | #endif 49 | 50 | #ifdef MOUSE_INTERFACE 51 | usb_mouse_class Mouse; 52 | #endif 53 | 54 | #ifdef RAWHID_INTERFACE 55 | usb_rawhid_class RawHID; 56 | #endif 57 | 58 | #ifdef FLIGHTSIM_INTERFACE 59 | FlightSimClass FlightSim; 60 | #endif 61 | 62 | #ifdef SEREMU_INTERFACE 63 | usb_seremu_class Serial; 64 | #endif 65 | 66 | #ifdef JOYSTICK_INTERFACE 67 | usb_joystick_class Joystick; 68 | uint8_t usb_joystick_class::manual_mode = 0; 69 | #endif 70 | 71 | #ifdef USB_DISABLED 72 | usb_serial_class Serial; 73 | #endif 74 | 75 | 76 | #else // F_CPU < 20 MHz 77 | 78 | #if defined(USB_SERIAL) || defined(USB_SERIAL_HID) 79 | usb_serial_class Serial; 80 | #elif (USB_DISABLED) 81 | usb_serial_class Serial; 82 | #else 83 | usb_seremu_class Serial; 84 | #endif 85 | 86 | #endif // F_CPU 87 | 88 | void serialEvent() __attribute__((weak)); 89 | void serialEvent() {} 90 | -------------------------------------------------------------------------------- /usb_joystick.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "usb_dev.h" 32 | #include "usb_joystick.h" 33 | #include "core_pins.h" // for yield() 34 | #include "HardwareSerial.h" 35 | #include // for memcpy() 36 | 37 | #ifdef JOYSTICK_INTERFACE // defined by usb_dev.h -> usb_desc.h 38 | #if F_CPU >= 20000000 39 | 40 | uint32_t usb_joystick_data[3]; 41 | 42 | 43 | // Maximum number of transmit packets to queue so we don't starve other endpoints for memory 44 | #define TX_PACKET_LIMIT 3 45 | 46 | static uint8_t transmit_previous_timeout=0; 47 | 48 | // When the PC isn't listening, how long do we wait before discarding data? 49 | #define TX_TIMEOUT_MSEC 30 50 | 51 | #if F_CPU == 168000000 52 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100) 53 | #elif F_CPU == 144000000 54 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932) 55 | #elif F_CPU == 120000000 56 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 764) 57 | #elif F_CPU == 96000000 58 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) 59 | #elif F_CPU == 72000000 60 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) 61 | #elif F_CPU == 48000000 62 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) 63 | #elif F_CPU == 24000000 64 | #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) 65 | #endif 66 | 67 | 68 | 69 | int usb_joystick_send(void) 70 | { 71 | uint32_t wait_count=0; 72 | usb_packet_t *tx_packet; 73 | 74 | //serial_print("send"); 75 | //serial_print("\n"); 76 | while (1) { 77 | if (!usb_configuration) { 78 | //serial_print("error1\n"); 79 | return -1; 80 | } 81 | if (usb_tx_packet_count(JOYSTICK_ENDPOINT) < TX_PACKET_LIMIT) { 82 | tx_packet = usb_malloc(); 83 | if (tx_packet) break; 84 | } 85 | if (++wait_count > TX_TIMEOUT || transmit_previous_timeout) { 86 | transmit_previous_timeout = 1; 87 | //serial_print("error2\n"); 88 | return -1; 89 | } 90 | yield(); 91 | } 92 | transmit_previous_timeout = 0; 93 | memcpy(tx_packet->buf, usb_joystick_data, 12); 94 | tx_packet->len = 12; 95 | usb_tx(JOYSTICK_ENDPOINT, tx_packet); 96 | //serial_print("ok\n"); 97 | return 0; 98 | } 99 | 100 | 101 | 102 | #endif // F_CPU 103 | #endif // JOYSTICK_INTERFACE 104 | -------------------------------------------------------------------------------- /usb_mem.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "usb_dev.h" 32 | #if F_CPU >= 20000000 && defined(NUM_ENDPOINTS) 33 | 34 | #include "kinetis.h" 35 | //#include "HardwareSerial.h" 36 | #include "usb_mem.h" 37 | 38 | __attribute__ ((section(".usbbuffers"), used)) 39 | unsigned char usb_buffer_memory[NUM_USB_BUFFERS * sizeof(usb_packet_t)]; 40 | 41 | static uint32_t usb_buffer_available = 0xFFFFFFFF; 42 | 43 | // use bitmask and CLZ instruction to implement fast free list 44 | // http://www.archivum.info/gnu.gcc.help/2006-08/00148/Re-GCC-Inline-Assembly.html 45 | // http://gcc.gnu.org/ml/gcc/2012-06/msg00015.html 46 | // __builtin_clz() 47 | 48 | usb_packet_t * usb_malloc(void) 49 | { 50 | unsigned int n, avail; 51 | uint8_t *p; 52 | 53 | __disable_irq(); 54 | avail = usb_buffer_available; 55 | n = __builtin_clz(avail); // clz = count leading zeros 56 | if (n >= NUM_USB_BUFFERS) { 57 | __enable_irq(); 58 | return NULL; 59 | } 60 | //serial_print("malloc:"); 61 | //serial_phex(n); 62 | //serial_print("\n"); 63 | 64 | usb_buffer_available = avail & ~(0x80000000 >> n); 65 | __enable_irq(); 66 | p = usb_buffer_memory + (n * sizeof(usb_packet_t)); 67 | //serial_print("malloc:"); 68 | //serial_phex32((int)p); 69 | //serial_print("\n"); 70 | *(uint32_t *)p = 0; 71 | *(uint32_t *)(p + 4) = 0; 72 | return (usb_packet_t *)p; 73 | } 74 | 75 | // for the receive endpoints to request memory 76 | extern uint8_t usb_rx_memory_needed; 77 | extern void usb_rx_memory(usb_packet_t *packet); 78 | 79 | void usb_free(usb_packet_t *p) 80 | { 81 | unsigned int n, mask; 82 | 83 | //serial_print("free:"); 84 | n = ((uint8_t *)p - usb_buffer_memory) / sizeof(usb_packet_t); 85 | if (n >= NUM_USB_BUFFERS) return; 86 | //serial_phex(n); 87 | //serial_print("\n"); 88 | 89 | // if any endpoints are starving for memory to receive 90 | // packets, give this memory to them immediately! 91 | if (usb_rx_memory_needed && usb_configuration) { 92 | //serial_print("give to rx:"); 93 | //serial_phex32((int)p); 94 | //serial_print("\n"); 95 | usb_rx_memory(p); 96 | return; 97 | } 98 | 99 | mask = (0x80000000 >> n); 100 | __disable_irq(); 101 | usb_buffer_available |= mask; 102 | __enable_irq(); 103 | 104 | //serial_print("free:"); 105 | //serial_phex32((int)p); 106 | //serial_print("\n"); 107 | } 108 | 109 | #endif // F_CPU >= 20 MHz && defined(NUM_ENDPOINTS) 110 | -------------------------------------------------------------------------------- /usb_mem.h: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #ifndef _usb_mem_h_ 32 | #define _usb_mem_h_ 33 | 34 | #include 35 | 36 | typedef struct usb_packet_struct { 37 | uint16_t len; 38 | uint16_t index; 39 | struct usb_packet_struct *next; 40 | uint8_t buf[64]; 41 | } usb_packet_t; 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | usb_packet_t * usb_malloc(void); 48 | void usb_free(usb_packet_t *p); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /usb_mtp.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2015 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "usb_dev.h" 32 | #include "usb_mtp.h" 33 | #include "core_pins.h" // for yield() 34 | #include "HardwareSerial.h" 35 | 36 | #ifdef MTP_INTERFACE // defined by usb_dev.h -> usb_desc.h 37 | #if F_CPU >= 20000000 38 | 39 | void usb_mtp_update(void) 40 | { 41 | serial_print("test\n"); 42 | 43 | // TODO: a lot of work here.... 44 | 45 | 46 | 47 | } 48 | 49 | 50 | #endif // F_CPU 51 | #endif // MTP_INTERFACE 52 | -------------------------------------------------------------------------------- /usb_mtp.h: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #ifndef USB_MTP_h_ 32 | #define USB_MTP_h_ 33 | 34 | #include "usb_desc.h" 35 | 36 | #if defined(MTP_INTERFACE) 37 | 38 | #include 39 | 40 | 41 | // C language implementation 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | void usb_mtp_update(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | // C++ interface 53 | #ifdef __cplusplus 54 | class usb_mpt_class 55 | { 56 | public: 57 | void begin(void) { } 58 | void end(void) { } 59 | void update() __attribute__((always_inline)) { 60 | usb_mtp_update(); 61 | } 62 | private: 63 | }; 64 | 65 | extern usb_mpt_class MTPDisk; 66 | 67 | 68 | #endif // __cplusplus 69 | 70 | #endif // MTP_INTERFACE 71 | 72 | #endif // USB_MTP_h_ 73 | 74 | -------------------------------------------------------------------------------- /usb_names.h: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #ifndef _usb_names_h_ 32 | #define _usb_names_h_ 33 | 34 | // These definitions are intended to allow users to override the default 35 | // USB manufacturer, product and serial number strings. 36 | 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | struct usb_string_descriptor_struct { 44 | uint8_t bLength; 45 | uint8_t bDescriptorType; 46 | uint16_t wString[]; 47 | }; 48 | 49 | extern struct usb_string_descriptor_struct usb_string_manufacturer_name; 50 | extern struct usb_string_descriptor_struct usb_string_product_name; 51 | extern struct usb_string_descriptor_struct usb_string_serial_number; 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /usb_rawhid.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "usb_dev.h" 32 | #include "usb_rawhid.h" 33 | #include "core_pins.h" // for yield(), millis() 34 | #include // for memcpy() 35 | //#include "HardwareSerial.h" 36 | 37 | #ifdef RAWHID_INTERFACE // defined by usb_dev.h -> usb_desc.h 38 | #if F_CPU >= 20000000 39 | 40 | int usb_rawhid_recv(void *buffer, uint32_t timeout) 41 | { 42 | usb_packet_t *rx_packet; 43 | uint32_t begin = millis(); 44 | 45 | while (1) { 46 | if (!usb_configuration) return -1; 47 | rx_packet = usb_rx(RAWHID_RX_ENDPOINT); 48 | if (rx_packet) break; 49 | if (millis() - begin > timeout || !timeout) return 0; 50 | yield(); 51 | } 52 | memcpy(buffer, rx_packet->buf, RAWHID_RX_SIZE); 53 | usb_free(rx_packet); 54 | return RAWHID_RX_SIZE; 55 | } 56 | 57 | int usb_rawhid_available(void) 58 | { 59 | uint32_t count; 60 | 61 | if (!usb_configuration) return 0; 62 | count = usb_rx_byte_count(RAWHID_RX_ENDPOINT); 63 | return count; 64 | } 65 | 66 | // Maximum number of transmit packets to queue so we don't starve other endpoints for memory 67 | #define TX_PACKET_LIMIT 4 68 | 69 | int usb_rawhid_send(const void *buffer, uint32_t timeout) 70 | { 71 | usb_packet_t *tx_packet; 72 | uint32_t begin = millis(); 73 | 74 | while (1) { 75 | if (!usb_configuration) return -1; 76 | if (usb_tx_packet_count(RAWHID_TX_ENDPOINT) < TX_PACKET_LIMIT) { 77 | tx_packet = usb_malloc(); 78 | if (tx_packet) break; 79 | } 80 | if (millis() - begin > timeout) return 0; 81 | yield(); 82 | } 83 | memcpy(tx_packet->buf, buffer, RAWHID_TX_SIZE); 84 | tx_packet->len = RAWHID_TX_SIZE; 85 | usb_tx(RAWHID_TX_ENDPOINT, tx_packet); 86 | return RAWHID_TX_SIZE; 87 | } 88 | 89 | #endif // F_CPU 90 | #endif // RAWHID_INTERFACE 91 | -------------------------------------------------------------------------------- /usb_rawhid.h: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #ifndef USBrawhid_h_ 32 | #define USBrawhid_h_ 33 | 34 | #include "usb_desc.h" 35 | 36 | #if defined(RAWHID_INTERFACE) 37 | 38 | #include 39 | 40 | // C language implementation 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | int usb_rawhid_recv(void *buffer, uint32_t timeout); 45 | int usb_rawhid_available(void); 46 | int usb_rawhid_send(const void *buffer, uint32_t timeout); 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | 52 | // C++ interface 53 | #ifdef __cplusplus 54 | class usb_rawhid_class 55 | { 56 | public: 57 | int available(void) {return usb_rawhid_available(); } 58 | int recv(void *buffer, uint16_t timeout) { return usb_rawhid_recv(buffer, timeout); } 59 | int send(const void *buffer, uint16_t timeout) { return usb_rawhid_send(buffer, timeout); } 60 | }; 61 | 62 | extern usb_rawhid_class RawHID; 63 | 64 | #endif // __cplusplus 65 | 66 | #endif // RAWHID_INTERFACE 67 | 68 | #endif // USBrawhid_h_ 69 | -------------------------------------------------------------------------------- /util/atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is port of Dean Camera's ATOMIC_BLOCK macros for AVR to ARM Cortex M3 3 | * v1.0 4 | * Mark Pendrith, Nov 27, 2012. 5 | * 6 | * From Mark: 7 | * >When I ported the macros I emailed Dean to ask what attribution would be 8 | * >appropriate, and here is his response: 9 | * > 10 | * >>Mark, 11 | * >>I think it's great that you've ported the macros; consider them 12 | * >>public domain, to do with whatever you wish. I hope you find them >useful . 13 | * >> 14 | * >>Cheers! 15 | * >>- Dean 16 | */ 17 | 18 | #ifdef __arm__ 19 | #ifndef _CORTEX_M3_ATOMIC_H_ 20 | #define _CORTEX_M3_ATOMIC_H_ 21 | 22 | static __inline__ uint32_t __get_primask(void) \ 23 | { uint32_t primask = 0; \ 24 | __asm__ volatile ("MRS %[result], PRIMASK\n\t":[result]"=r"(primask)::); \ 25 | return primask; } // returns 0 if interrupts enabled, 1 if disabled 26 | 27 | static __inline__ void __set_primask(uint32_t setval) \ 28 | { __asm__ volatile ("MSR PRIMASK, %[value]\n\t""dmb\n\t""dsb\n\t""isb\n\t"::[value]"r"(setval):); 29 | __asm__ volatile ("" ::: "memory");} 30 | 31 | static __inline__ uint32_t __iSeiRetVal(void) \ 32 | { __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \ 33 | __asm__ volatile ("" ::: "memory"); return 1; } 34 | 35 | static __inline__ uint32_t __iCliRetVal(void) \ 36 | { __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \ 37 | __asm__ volatile ("" ::: "memory"); return 1; } 38 | 39 | static __inline__ void __iSeiParam(const uint32_t *__s) \ 40 | { __asm__ volatile ("CPSIE i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \ 41 | __asm__ volatile ("" ::: "memory"); (void)__s; } 42 | 43 | static __inline__ void __iCliParam(const uint32_t *__s) \ 44 | { __asm__ volatile ("CPSID i\n\t""dmb\n\t""dsb\n\t""isb\n\t"); \ 45 | __asm__ volatile ("" ::: "memory"); (void)__s; } 46 | 47 | static __inline__ void __iRestore(const uint32_t *__s) \ 48 | { __set_primask(*__s); __asm__ volatile ("dmb\n\t""dsb\n\t""isb\n\t"); \ 49 | __asm__ volatile ("" ::: "memory"); } 50 | 51 | 52 | #define ATOMIC_BLOCK(type) \ 53 | for ( type, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 ) 54 | 55 | #define ATOMIC_RESTORESTATE \ 56 | uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask() 57 | 58 | #define ATOMIC_FORCEON \ 59 | uint32_t primask_save __attribute__((__cleanup__(__iSeiParam))) = 0 60 | 61 | #define NONATOMIC_BLOCK(type) \ 62 | for ( type, __ToDo = __iSeiRetVal(); __ToDo ; __ToDo = 0 ) 63 | 64 | #define NONATOMIC_RESTORESTATE \ 65 | uint32_t primask_save __attribute__((__cleanup__(__iRestore))) = __get_primask() 66 | 67 | #define NONATOMIC_FORCEOFF \ 68 | uint32_t primask_save __attribute__((__cleanup__(__iCliParam))) = 0 69 | 70 | #endif 71 | #endif 72 | -------------------------------------------------------------------------------- /util/crc16.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_CRC16_H_ 2 | #define _UTIL_CRC16_H_ 3 | 4 | #include 5 | 6 | static inline uint16_t _crc16_update(uint16_t crc, uint8_t data) __attribute__((always_inline, unused)); 7 | static inline uint16_t _crc16_update(uint16_t crc, uint8_t data) 8 | { 9 | unsigned int i; 10 | 11 | crc ^= data; 12 | for (i = 0; i < 8; ++i) { 13 | if (crc & 1) { 14 | crc = (crc >> 1) ^ 0xA001; 15 | } else { 16 | crc = (crc >> 1); 17 | } 18 | } 19 | return crc; 20 | } 21 | 22 | static inline uint16_t _crc_xmodem_update(uint16_t crc, uint8_t data) __attribute__((always_inline, unused)); 23 | static inline uint16_t _crc_xmodem_update(uint16_t crc, uint8_t data) 24 | { 25 | unsigned int i; 26 | 27 | crc = crc ^ ((uint16_t)data << 8); 28 | for (i=0; i<8; i++) { 29 | if (crc & 0x8000) { 30 | crc = (crc << 1) ^ 0x1021; 31 | } else { 32 | crc <<= 1; 33 | } 34 | } 35 | return crc; 36 | } 37 | 38 | static inline uint16_t _crc_ccitt_update (uint16_t crc, uint8_t data) __attribute__((always_inline, unused)); 39 | static inline uint16_t _crc_ccitt_update (uint16_t crc, uint8_t data) 40 | { 41 | data ^= (crc & 255); 42 | data ^= data << 4; 43 | 44 | return ((((uint16_t)data << 8) | (crc >> 8)) ^ (uint8_t)(data >> 4) 45 | ^ ((uint16_t)data << 3)); 46 | } 47 | 48 | static inline uint8_t _crc_ibutton_update(uint8_t crc, uint8_t data) __attribute__((always_inline, unused)); 49 | static inline uint8_t _crc_ibutton_update(uint8_t crc, uint8_t data) 50 | { 51 | unsigned int i; 52 | 53 | crc = crc ^ data; 54 | for (i = 0; i < 8; i++) { 55 | if (crc & 0x01) { 56 | crc = (crc >> 1) ^ 0x8C; 57 | } else { 58 | crc >>= 1; 59 | } 60 | } 61 | return crc; 62 | } 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /util/delay.h: -------------------------------------------------------------------------------- 1 | #ifndef _delay_us 2 | #define _delay_us(n) delayMicroseconds(n) 3 | #endif 4 | 5 | #ifndef _delay_ms 6 | #define _delay_ms(n) delay(n) 7 | #endif 8 | -------------------------------------------------------------------------------- /util/parity.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_PARITY_H_ 2 | #define _UTIL_PARITY_H_ 3 | 4 | static inline uint8_t parity_even_bit(uint8_t x) __attribute__((pure, always_inline, unused)); 5 | static inline uint8_t parity_even_bit(uint8_t x) 6 | { 7 | x ^= x >> 1; 8 | x ^= x >> 2; 9 | x ^= x >> 4; 10 | return x & 1; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /utility/direct_pin_read.h: -------------------------------------------------------------------------------- 1 | #ifndef direct_pin_read_h_ 2 | #define direct_pin_read_h_ 3 | 4 | #if defined(__AVR__) || defined(__MK20DX128__) || defined(__MK20DX256__) 5 | 6 | #define IO_REG_TYPE uint8_t 7 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 8 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 9 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 10 | 11 | #elif defined(__SAM3X8E__) 12 | 13 | #define IO_REG_TYPE uint32_t 14 | #define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin))) 15 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 16 | #define DIRECT_PIN_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0) 17 | 18 | #elif defined(__PIC32MX__) 19 | 20 | #define IO_REG_TYPE uint32_t 21 | #define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin))) 22 | #define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin)) 23 | #define DIRECT_PIN_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0) 24 | 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /utility/interrupt_config.h: -------------------------------------------------------------------------------- 1 | #if defined(__AVR__) 2 | 3 | #include 4 | #include 5 | 6 | #define attachInterrupt(num, func, mode) enableInterrupt(num) 7 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 8 | #define SCRAMBLE_INT_ORDER(num) ((num < 4) ? num + 2 : ((num < 6) ? num - 4 : num)) 9 | #define DESCRAMBLE_INT_ORDER(num) ((num < 2) ? num + 4 : ((num < 6) ? num - 2 : num)) 10 | #else 11 | #define SCRAMBLE_INT_ORDER(num) (num) 12 | #define DESCRAMBLE_INT_ORDER(num) (num) 13 | #endif 14 | 15 | static void enableInterrupt(uint8_t num) 16 | { 17 | switch (DESCRAMBLE_INT_ORDER(num)) { 18 | #if defined(EICRA) && defined(EIMSK) 19 | case 0: 20 | EICRA = (EICRA & 0xFC) | 0x01; 21 | EIMSK |= 0x01; 22 | return; 23 | case 1: 24 | EICRA = (EICRA & 0xF3) | 0x04; 25 | EIMSK |= 0x02; 26 | return; 27 | case 2: 28 | EICRA = (EICRA & 0xCF) | 0x10; 29 | EIMSK |= 0x04; 30 | return; 31 | case 3: 32 | EICRA = (EICRA & 0x3F) | 0x40; 33 | EIMSK |= 0x08; 34 | return; 35 | #elif defined(MCUCR) && defined(GICR) 36 | case 0: 37 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 38 | GICR |= (1 << INT0); 39 | return; 40 | case 1: 41 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 42 | GICR |= (1 << INT1); 43 | return; 44 | #elif defined(MCUCR) && defined(GIMSK) 45 | case 0: 46 | MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); 47 | GIMSK |= (1 << INT0); 48 | return; 49 | case 1: 50 | MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); 51 | GIMSK |= (1 << INT1); 52 | return; 53 | #endif 54 | #if defined(EICRB) && defined(EIMSK) 55 | case 4: 56 | EICRB = (EICRB & 0xFC) | 0x01; 57 | EIMSK |= 0x10; 58 | return; 59 | case 5: 60 | EICRB = (EICRB & 0xF3) | 0x04; 61 | EIMSK |= 0x20; 62 | return; 63 | case 6: 64 | EICRB = (EICRB & 0xCF) | 0x10; 65 | EIMSK |= 0x40; 66 | return; 67 | case 7: 68 | EICRB = (EICRB & 0x3F) | 0x40; 69 | EIMSK |= 0x80; 70 | return; 71 | #endif 72 | } 73 | } 74 | 75 | #elif defined(__PIC32MX__) 76 | 77 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 78 | #undef ENCODER_OPTIMIZE_INTERRUPTS 79 | #endif 80 | 81 | #else 82 | 83 | #ifdef ENCODER_OPTIMIZE_INTERRUPTS 84 | #undef ENCODER_OPTIMIZE_INTERRUPTS 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /wiring_private.h: -------------------------------------------------------------------------------- 1 | #ifndef WiringPrivate_h 2 | #define WiringPrivate_h 3 | 4 | #include 5 | #include 6 | 7 | #include "wiring.h" 8 | 9 | #ifndef cbi 10 | #define cbi(sfr, bit) ((sfr) &= ~_BV(bit)) 11 | #endif 12 | #ifndef sbi 13 | #define sbi(sfr, bit) ((sfr) |= _BV(bit)) 14 | #endif 15 | 16 | typedef void (*voidFuncPtr)(void); 17 | 18 | #endif 19 | 20 | 21 | -------------------------------------------------------------------------------- /yield.c: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2013 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | void yield(void) __attribute__ ((weak)); 32 | void yield(void) {}; 33 | -------------------------------------------------------------------------------- /yield.cpp: -------------------------------------------------------------------------------- 1 | /* Teensyduino Core Library 2 | * http://www.pjrc.com/teensy/ 3 | * Copyright (c) 2014 PJRC.COM, LLC. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * 1. The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * 2. If the Software is incorporated into a build system that allows 17 | * selection among a list of target devices, then similar target 18 | * devices manufactured by PJRC.COM must be included in the list of 19 | * target devices and selectable in the same manner. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | * SOFTWARE. 29 | */ 30 | 31 | #include "core_pins.h" 32 | #include "HardwareSerial.h" 33 | #include "usb_serial.h" 34 | #include "usb_seremu.h" 35 | 36 | void yield(void) __attribute__ ((weak)); 37 | void yield(void) 38 | { 39 | static uint8_t running=0; 40 | 41 | if (running) return; // TODO: does this need to be atomic? 42 | running = 1; 43 | if (Serial.available()) serialEvent(); 44 | if (Serial1.available()) serialEvent1(); 45 | if (Serial2.available()) serialEvent2(); 46 | if (Serial3.available()) serialEvent3(); 47 | running = 0; 48 | }; 49 | --------------------------------------------------------------------------------