├── LICENSE.md ├── README.md ├── boards.txt ├── cores └── arduino │ ├── Arduino.h │ ├── Client.h │ ├── HardwareSerial.cpp │ ├── HardwareSerial.h │ ├── IPAddress.cpp │ ├── IPAddress.h │ ├── Print.cpp │ ├── Print.h │ ├── Printable.h │ ├── RingBuffer.cpp │ ├── RingBuffer.h │ ├── Server.h │ ├── Stream.cpp │ ├── Stream.h │ ├── Tone.cpp │ ├── Tone.h │ ├── Udp.h │ ├── WCharacter.h │ ├── WInterrupts.c │ ├── WInterrupts.h │ ├── WMath.cpp │ ├── WMath.h │ ├── WString.cpp │ ├── WString.h │ ├── abi.cpp │ ├── avr │ ├── dtostrf.c │ ├── dtostrf.h │ └── pgmspace.h │ ├── binary.h │ ├── board.c │ ├── board.h │ ├── hooks.c │ ├── itoa.c │ ├── itoa.h │ ├── main.cpp │ ├── new.cpp │ ├── pins_arduino.c │ ├── pins_arduino.h │ ├── stm8 │ ├── PeripheralPins.h │ ├── PinAF_STM8Lxx.h │ ├── PinConfigured.c │ ├── PinConfigured.h │ ├── PinNames.h │ ├── PinNamesTypes.h │ ├── PortNames.c │ ├── PortNames.h │ ├── STM8_StdPeriph_Driver │ │ ├── stm8xx_adc.c │ │ ├── stm8xx_aes.c │ │ ├── stm8xx_awu.c │ │ ├── stm8xx_beep.c │ │ ├── stm8xx_can.c │ │ ├── stm8xx_clk.c │ │ ├── stm8xx_comp.c │ │ ├── stm8xx_dac.c │ │ ├── stm8xx_dma.c │ │ ├── stm8xx_exti.c │ │ ├── stm8xx_flash.c │ │ ├── stm8xx_gpio.c │ │ ├── stm8xx_i2c.c │ │ ├── stm8xx_irtim.c │ │ ├── stm8xx_itc.c │ │ ├── stm8xx_iwdg.c │ │ ├── stm8xx_lcd.c │ │ ├── stm8xx_pwr.c │ │ ├── stm8xx_rst.c │ │ ├── stm8xx_rtc.c │ │ ├── stm8xx_spi.c │ │ ├── stm8xx_syscfg.c │ │ ├── stm8xx_tim1.c │ │ ├── stm8xx_tim2.c │ │ ├── stm8xx_tim3.c │ │ ├── stm8xx_tim4.c │ │ ├── stm8xx_tim5.c │ │ ├── stm8xx_tim6.c │ │ ├── stm8xx_uart1.c │ │ ├── stm8xx_uart2.c │ │ ├── stm8xx_uart3.c │ │ ├── stm8xx_uart4.c │ │ ├── stm8xx_usart.c │ │ ├── stm8xx_wfe.c │ │ └── stm8xx_wwdg.c │ ├── analog.c │ ├── analog.h │ ├── clock.c │ ├── clock.h │ ├── digital_io.c │ ├── digital_io.h │ ├── hw_config.c │ ├── hw_config.h │ ├── interrupt.c │ ├── interrupt.h │ ├── pinmap.c │ ├── pinmap.h │ ├── spi_com.c │ ├── spi_com.h │ ├── stm8_def.c │ ├── stm8_def.h │ ├── stm8_eeprom.c │ ├── stm8_eeprom.h │ ├── stm8_it.c │ ├── stm8_it.h │ ├── timer.c │ ├── timer.h │ ├── twi.c │ ├── twi.h │ ├── uart.c │ └── uart.h │ ├── syscalls_stm8.c │ ├── utils.h │ ├── wiring.h │ ├── wiring_analog.c │ ├── wiring_analog.h │ ├── wiring_constants.h │ ├── wiring_digital.c │ ├── wiring_digital.h │ ├── wiring_private.h │ ├── wiring_pulse.cpp │ ├── wiring_pulse.h │ ├── wiring_shift.c │ ├── wiring_shift.h │ ├── wiring_time.c │ └── wiring_time.h ├── libraries ├── CapacitiveSensor-0.5.1 │ ├── CapacitiveSensor.cpp │ ├── CapacitiveSensor.h │ ├── README.md │ ├── examples │ │ └── CapacitiveSensorSketch │ │ │ └── CapacitiveSensorSketch.pde │ ├── keywords.txt │ └── library.properties ├── EEPROM │ ├── EEPROM.h │ ├── README.md │ ├── examples │ │ ├── eeprom_clear │ │ │ └── eeprom_clear.ino │ │ ├── eeprom_crc │ │ │ └── eeprom_crc.ino │ │ ├── eeprom_get │ │ │ └── eeprom_get.ino │ │ ├── eeprom_iteration │ │ │ └── eeprom_iteration.ino │ │ ├── eeprom_put │ │ │ └── eeprom_put.ino │ │ ├── eeprom_read │ │ │ └── eeprom_read.ino │ │ ├── eeprom_update │ │ │ └── eeprom_update.ino │ │ └── eeprom_write │ │ │ └── eeprom_write.ino │ ├── keywords.txt │ └── library.properties ├── SPI │ ├── README.md │ ├── examples │ │ ├── BarometricPressureSensor │ │ │ └── BarometricPressureSensor.ino │ │ └── DigitalPotControl │ │ │ └── DigitalPotControl.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── SPI.cpp │ │ └── SPI.h ├── Servo │ ├── README.adoc │ ├── examples │ │ ├── Knob │ │ │ └── Knob.ino │ │ ├── Sweep │ │ │ └── Sweep.ino │ │ └── fs90r │ │ │ └── fs90r.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── Servo.h │ │ ├── avr │ │ ├── Servo.cpp │ │ └── ServoTimers.h │ │ ├── sam │ │ ├── Servo.cpp │ │ └── ServoTimers.h │ │ ├── samd │ │ ├── Servo.cpp │ │ └── ServoTimers.h │ │ └── stm8 │ │ ├── Servo.cpp │ │ └── ServoTimers.h └── Wire │ ├── examples │ ├── SFRRanger_reader │ │ └── SFRRanger_reader.pde │ ├── digital_potentiometer │ │ └── digital_potentiometer.pde │ ├── master_reader │ │ └── master_reader.pde │ ├── master_reader_writer │ │ └── master_reader_writer.ino │ ├── master_writer │ │ └── master_writer.pde │ ├── slave_receiver │ │ └── slave_receiver.pde │ ├── slave_sender │ │ └── slave_sender.pde │ └── slave_sender_receiver │ │ └── slave_sender_receiver.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ ├── Wire.cpp │ └── Wire.h ├── platform.txt ├── programmers.txt ├── system └── Drivers │ ├── STM8Lxx_StdPeriph_Driver │ ├── Release_Notes.html │ ├── inc │ │ ├── stm8l15x.h │ │ ├── stm8l15x_adc.h │ │ ├── stm8l15x_aes.h │ │ ├── stm8l15x_beep.h │ │ ├── stm8l15x_clk.h │ │ ├── stm8l15x_comp.h │ │ ├── stm8l15x_dac.h │ │ ├── stm8l15x_dma.h │ │ ├── stm8l15x_exti.h │ │ ├── stm8l15x_flash.h │ │ ├── stm8l15x_gpio.h │ │ ├── stm8l15x_i2c.h │ │ ├── stm8l15x_irtim.h │ │ ├── stm8l15x_itc.h │ │ ├── stm8l15x_iwdg.h │ │ ├── stm8l15x_lcd.h │ │ ├── stm8l15x_pwr.h │ │ ├── stm8l15x_rst.h │ │ ├── stm8l15x_rtc.h │ │ ├── stm8l15x_spi.h │ │ ├── stm8l15x_syscfg.h │ │ ├── stm8l15x_tim1.h │ │ ├── stm8l15x_tim2.h │ │ ├── stm8l15x_tim3.h │ │ ├── stm8l15x_tim4.h │ │ ├── stm8l15x_tim5.h │ │ ├── stm8l15x_usart.h │ │ ├── stm8l15x_wfe.h │ │ └── stm8l15x_wwdg.h │ └── src │ │ ├── stm8l15x_adc.c │ │ ├── stm8l15x_aes.c │ │ ├── stm8l15x_beep.c │ │ ├── stm8l15x_clk.c │ │ ├── stm8l15x_comp.c │ │ ├── stm8l15x_dac.c │ │ ├── stm8l15x_dma.c │ │ ├── stm8l15x_exti.c │ │ ├── stm8l15x_flash.c │ │ ├── stm8l15x_gpio.c │ │ ├── stm8l15x_i2c.c │ │ ├── stm8l15x_irtim.c │ │ ├── stm8l15x_itc.c │ │ ├── stm8l15x_iwdg.c │ │ ├── stm8l15x_lcd.c │ │ ├── stm8l15x_pwr.c │ │ ├── stm8l15x_rst.c │ │ ├── stm8l15x_rtc.c │ │ ├── stm8l15x_spi.c │ │ ├── stm8l15x_syscfg.c │ │ ├── stm8l15x_tim1.c │ │ ├── stm8l15x_tim2.c │ │ ├── stm8l15x_tim3.c │ │ ├── stm8l15x_tim4.c │ │ ├── stm8l15x_tim5.c │ │ ├── stm8l15x_usart.c │ │ ├── stm8l15x_wfe.c │ │ └── stm8l15x_wwdg.c │ └── STM8Sxx_StdPeriph_Driver │ ├── Release_Notes.html │ ├── inc │ ├── stm8s.h │ ├── stm8s_adc1.h │ ├── stm8s_adc2.h │ ├── stm8s_awu.h │ ├── stm8s_beep.h │ ├── stm8s_can.h │ ├── stm8s_clk.h │ ├── stm8s_exti.h │ ├── stm8s_flash.h │ ├── stm8s_gpio.h │ ├── stm8s_i2c.h │ ├── stm8s_itc.h │ ├── stm8s_iwdg.h │ ├── stm8s_rst.h │ ├── stm8s_spi.h │ ├── stm8s_tim1.h │ ├── stm8s_tim2.h │ ├── stm8s_tim3.h │ ├── stm8s_tim4.h │ ├── stm8s_tim5.h │ ├── stm8s_tim6.h │ ├── stm8s_uart1.h │ ├── stm8s_uart2.h │ ├── stm8s_uart3.h │ ├── stm8s_uart4.h │ └── stm8s_wwdg.h │ └── src │ ├── stm8s_adc1.c │ ├── stm8s_adc2.c │ ├── stm8s_awu.c │ ├── stm8s_beep.c │ ├── stm8s_can.c │ ├── stm8s_clk.c │ ├── stm8s_exti.c │ ├── stm8s_flash.c │ ├── stm8s_gpio.c │ ├── stm8s_i2c.c │ ├── stm8s_itc.c │ ├── stm8s_iwdg.c │ ├── stm8s_rst.c │ ├── stm8s_spi.c │ ├── stm8s_tim1.c │ ├── stm8s_tim2.c │ ├── stm8s_tim3.c │ ├── stm8s_tim4.c │ ├── stm8s_tim5.c │ ├── stm8s_tim6.c │ ├── stm8s_uart1.c │ ├── stm8s_uart2.c │ ├── stm8s_uart3.c │ ├── stm8s_uart4.c │ └── stm8s_wwdg.c └── variants ├── NUCLEO_8L152R8 ├── PeripheralPins.c ├── lkfscript.lkf ├── stm8l15x_conf.h ├── stm8l15x_it.c ├── variant.cpp └── variant.h └── NUCLEO_8S208RB ├── PeripheralPins.c ├── lkfscript.lkf ├── stm8s_conf.h ├── stm8s_it.c ├── variant.cpp └── variant.h /LICENSE.md: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) (Year), (Name of copyright holder) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * 3. Neither the name of the copyright holder nor the names of its 15 | * contributors may be used to endorse or promote products derived 16 | * from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Important note 2 | 3 | **This repository has been archived as no further evolutions are planned.** 4 | 5 | **As an alternative, consider using [STM32C0xx series](https://www.st.com/en/microcontrollers-microprocessors/stm32c0-series.html) supported by the [Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32).** 6 | 7 | # Arduino core support for STM8 based boards 8 | [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM8.svg)](https://github.com/stm32duino/Arduino_Core_STM8/releases/latest) 9 | 10 | * [Introduction](https://github.com/stm32duino/Arduino_Core_STM8#Introduction)
11 | * [Getting Started](https://github.com/stm32duino/Arduino_Core_STM8#getting-started)
12 | * [Boards available](https://github.com/stm32duino/Arduino_Core_STM8#boards-available)
13 | * [Troubleshooting](https://github.com/stm32duino/Arduino_Core_STM8#troubleshooting)
14 | * [Wiki](https://github.com/stm32duino/wiki/wiki/) 15 | 16 | ## Introduction 17 | 18 | This repo adds the support of STM8 architecture in Arduino IDE.
19 | 20 | This porting is based on several external components : 21 | * STMicroelectronics Standard Peripheral Libraries (SPL) 22 | * [SPL for STM8L](https://www.st.com/en/embedded-software/stsw-stm8016.html) 23 | * [SPL for STM8S](https://www.st.com/en/embedded-software/stsw-stm8069.html) 24 | * Cosmic compiler, allowing to compile c++ source code on stm8 family (http://www.cosmic-software.com/) 25 | 26 | Solution is running on Windows only. 27 | 28 | ## Getting Started 29 | 30 | This repo is available as a package usable with [Arduino Boards Manager](https://www.arduino.cc/en/guide/cores). 31 | 32 | Use this link in the "*Additional Boards Managers URLs*" field: 33 | 34 | https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json 35 | 36 | **Warning**: 37 | * Default branch has changed to main. 38 | * Since core release 1.0.0 this link has changed. 39 | 40 | For full instructions on using the "**Boards Manager**", see the [Getting Started](https://github.com/stm32duino/wiki/wiki/Getting-Started) page. 41 | 42 | For advanced user, you can use the repository: see the [Using git repository](https://github.com/stm32duino/wiki/wiki/Using-git-repository) page. 43 | 44 | ## Boards available 45 | * STM8L 46 | * [Nucleo STM8L152R8](https://www.st.com/en/evaluation-tools/nucleo-8l152r8.html) 47 | 48 | * STM8S 49 | * [Nucleo STM8S208RB](https://www.st.com/en/evaluation-tools/nucleo-8s208rb.html) 50 | 51 | 52 | ## Troubleshooting and known issues 53 | 54 | Please note that this is a new core using a new compiler. You may face some issues with libraries compatibility.
55 | We have several known issues : 56 | * Windows 10: 57 | *Board binary may be corrupted when plugged on a Windows 10 machine. 58 | To ensure compatibility with Windows 10, please upgrade STLink with revision 2.32.22 or higher (estimated availability October 1st).* 59 | * Endianness: 60 | *STM8 microcontrollers are natively Big Endian whereas Arduino boards and STM32 microcontrollers are Little Endian. 61 | By default, some libraries don't handle endianess, therefore these won't be directly compatible with STM8 (this is the case of SD library for example).* 62 | 63 | If you have a question about compiler, you can also send a mail to Cosmic support : [send a mail to Cosmic support](mailto:support@cosmic.fr) 64 | 65 | -------------------------------------------------------------------------------- /cores/arduino/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2005-2013 Arduino Team. 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 Arduino_h 21 | #define Arduino_h 22 | 23 | #include "wiring.h" 24 | 25 | /* sketch */ 26 | 27 | #ifdef __cplusplus 28 | extern "C"{ 29 | #endif // __cplusplus 30 | extern void setup( void ) ; 31 | extern void loop( void ) ; 32 | extern void initVariant(void); 33 | extern void yield(void); 34 | #ifdef __cplusplus 35 | } // extern "C" 36 | #endif // __cplusplus 37 | 38 | // Include pins variant 39 | #include "pins_arduino.h" 40 | 41 | #endif // Arduino_h 42 | -------------------------------------------------------------------------------- /cores/arduino/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 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 client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream 27 | { 28 | 29 | public: 30 | virtual int connect(IPAddress ip, uint16_t port) = 0; 31 | virtual int connect(const char *host, uint16_t port) = 0; 32 | virtual size_t write(uint8_t) = 0; 33 | virtual size_t write(const uint8_t *buf, size_t size) = 0; 34 | virtual int available() = 0; 35 | virtual int read() = 0; 36 | virtual int read(uint8_t *buf, size_t size) = 0; 37 | virtual int peek() = 0; 38 | virtual void flush() = 0; 39 | virtual void stop() = 0; 40 | virtual uint8_t connected() = 0; 41 | virtual operator bool() = 0; 42 | 43 | protected: 44 | uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); }; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /cores/arduino/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.cpp - Base class that provides IPAddress 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 | #include 21 | #include 22 | 23 | IPAddress::IPAddress() 24 | { 25 | _address.dword = 0; 26 | } 27 | 28 | IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) 29 | { 30 | _address.bytes[0] = first_octet; 31 | _address.bytes[1] = second_octet; 32 | _address.bytes[2] = third_octet; 33 | _address.bytes[3] = fourth_octet; 34 | } 35 | 36 | IPAddress::IPAddress(uint32_t address) 37 | { 38 | _address.dword = address; 39 | } 40 | 41 | IPAddress::IPAddress(const uint8_t *address) 42 | { 43 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 44 | } 45 | 46 | bool IPAddress::fromString(const char *address) 47 | { 48 | // TODO: add support for "a", "a.b", "a.b.c" formats 49 | 50 | uint16_t acc = 0; // Accumulator 51 | uint8_t dots = 0; 52 | 53 | while (*address) 54 | { 55 | char c = *address++; 56 | if (c >= '0' && c <= '9') 57 | { 58 | acc = acc * 10 + (c - '0'); 59 | if (acc > 255) 60 | { 61 | // Value out of [0..255] range 62 | return false; 63 | } 64 | } 65 | else if (c == '.') 66 | { 67 | if (dots == 3) 68 | { 69 | // Too much dots (there must be 3 dots) 70 | return false; 71 | } 72 | _address.bytes[dots++] = acc; 73 | acc = 0; 74 | } 75 | else 76 | { 77 | // Invalid char 78 | return false; 79 | } 80 | } 81 | 82 | if (dots != 3) 83 | { 84 | // Too few dots (there must be 3 dots) 85 | return false; 86 | } 87 | _address.bytes[3] = acc; 88 | return true; 89 | } 90 | 91 | IPAddress &IPAddress::operator=(const uint8_t *address) 92 | { 93 | memcpy(_address.bytes, address, sizeof(_address.bytes)); 94 | return *this; 95 | } 96 | 97 | IPAddress &IPAddress::operator=(uint32_t address) 98 | { 99 | _address.dword = address; 100 | return *this; 101 | } 102 | 103 | bool IPAddress::operator==(const uint8_t *addr) const 104 | { 105 | return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; 106 | } 107 | 108 | size_t IPAddress::printTo(Print &p) const 109 | { 110 | size_t n = 0; 111 | for (int i = 0; i < 3; i++) 112 | { 113 | n += p.print(_address.bytes[i], DEC); 114 | n += p.print('.'); 115 | } 116 | n += p.print(_address.bytes[3], DEC); 117 | return n; 118 | } 119 | -------------------------------------------------------------------------------- /cores/arduino/IPAddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | IPAddress.h - Base class that provides IPAddress 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 IPAddress_h 21 | #define IPAddress_h 22 | 23 | #include 24 | #include "Printable.h" 25 | #include "WString.h" 26 | 27 | // A class to make it easier to handle and pass around IP addresses 28 | 29 | class IPAddress : public Printable 30 | { 31 | private: 32 | union { 33 | uint8_t bytes[4]; // IPv4 address 34 | uint32_t dword; 35 | } _address; 36 | 37 | // Access the raw byte array containing the address. Because this returns a pointer 38 | // to the internal structure rather than a copy of the address this function should only 39 | // be used when you know that the usage of the returned uint8_t* will be transient and not 40 | // stored. 41 | uint8_t *raw_address() { return _address.bytes; }; 42 | 43 | public: 44 | // Constructors 45 | IPAddress(); 46 | IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); 47 | IPAddress(uint32_t address); 48 | IPAddress(const uint8_t *address); 49 | 50 | bool fromString(const char *address); 51 | bool fromString(const String &address) { return fromString(address.c_str()); } 52 | 53 | // Overloaded cast operator to allow IPAddress objects to be used where a pointer 54 | // to a four-byte uint8_t array is expected 55 | operator uint32_t() const { return _address.dword; }; 56 | bool operator==(const IPAddress &addr) const { return _address.dword == addr._address.dword; }; 57 | bool operator==(const uint8_t *addr) const; 58 | 59 | // Overloaded index operator to allow getting and setting individual octets of the address 60 | uint8_t operator[](int index) const { return _address.bytes[index]; }; 61 | uint8_t &operator[](int index) { return _address.bytes[index]; }; 62 | 63 | // Overloaded copy operators to allow initialisation of IPAddress objects from other types 64 | IPAddress &operator=(const uint8_t *address); 65 | IPAddress &operator=(uint32_t address); 66 | 67 | virtual size_t printTo(Print &p) const; 68 | 69 | friend class EthernetClass; 70 | friend class UDP; 71 | friend class Client; 72 | friend class Server; 73 | friend class DhcpClass; 74 | friend class DNSClient; 75 | }; 76 | 77 | const IPAddress INADDR_NONE(0, 0, 0, 0); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /cores/arduino/Print.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 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 Print_h 21 | #define Print_h 22 | 23 | #include 24 | #include // for size_t 25 | 26 | #include "WString.h" 27 | #include "Printable.h" 28 | 29 | #define DEC 10 30 | #define HEX 16 31 | #define OCT 8 32 | #define BIN 2 33 | 34 | // uncomment next line to support printing of 64 bit ints. 35 | //#define SUPPORT_LONGLONG 36 | 37 | class Print 38 | { 39 | private: 40 | int write_error; 41 | size_t printNumber(unsigned long, uint8_t); 42 | #ifdef SUPPORT_LONGLONG 43 | void printLLNumber(uint64_t, uint8_t); 44 | #endif 45 | size_t printFloat(double, uint8_t); 46 | 47 | protected: 48 | void setWriteError(int err = 1) { write_error = err; } 49 | 50 | public: 51 | Print() : write_error(0) {} 52 | 53 | int getWriteError() { return write_error; } 54 | void clearWriteError() { setWriteError(0); } 55 | 56 | virtual size_t write(uint8_t) = 0; 57 | size_t write(const char *str) 58 | { 59 | if (str == NULL) 60 | return 0; 61 | return write((const uint8_t *)str, strlen(str)); 62 | } 63 | virtual size_t write(const uint8_t *buffer, size_t size); 64 | size_t write(const char *buffer, size_t size) 65 | { 66 | return write((const uint8_t *)buffer, size); 67 | } 68 | 69 | size_t print(const __FlashStringHelper *); 70 | size_t print(const String &); 71 | size_t print(const char[]); 72 | size_t print(char); 73 | size_t print(unsigned char, int = DEC); 74 | size_t print(int, int = DEC); 75 | size_t print(unsigned int, int = DEC); 76 | size_t print(long, int = DEC); 77 | size_t print(unsigned long, int = DEC); 78 | size_t print(double, int = 2); 79 | size_t print(const Printable &); 80 | 81 | size_t println(const __FlashStringHelper *); 82 | size_t println(const String &s); 83 | size_t println(const char[]); 84 | size_t println(char); 85 | size_t println(unsigned char, int = DEC); 86 | size_t println(int, int = DEC); 87 | size_t println(unsigned int, int = DEC); 88 | size_t println(long, int = DEC); 89 | size_t println(unsigned long, int = DEC); 90 | size_t println(double, int = 2); 91 | size_t println(const Printable &); 92 | size_t println(void); 93 | #ifdef SUPPORT_LONGLONG 94 | void println(int64_t, uint8_t = DEC); 95 | void print(int64_t, uint8_t = DEC); 96 | void println(uint64_t, uint8_t = DEC); 97 | void print(uint64_t, uint8_t = DEC); 98 | #endif 99 | }; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /cores/arduino/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 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print &p) const = 0; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /cores/arduino/RingBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "RingBuffer.h" 20 | #include 21 | 22 | RingBuffer::RingBuffer(void) 23 | { 24 | memset((void *)_aucBuffer, 0, SERIAL_BUFFER_SIZE); 25 | _iHead = 0; 26 | _iTail = 0; 27 | } 28 | 29 | void RingBuffer::store_char(uint8_t c) 30 | { 31 | int i = (uint32_t)(_iHead + 1) % SERIAL_BUFFER_SIZE; 32 | 33 | // if we should be storing the received character into the location 34 | // just before the tail (meaning that the head would advance to the 35 | // current location of the tail), we're about to overflow the buffer 36 | // and so we don't write the character or advance the head. 37 | if (i != _iTail) 38 | { 39 | _aucBuffer[_iHead] = c; 40 | _iHead = i; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cores/arduino/RingBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _RING_BUFFER_ 20 | #define _RING_BUFFER_ 21 | 22 | #include 23 | 24 | // Define constants and variables for buffering incoming serial data. We're 25 | // using a ring buffer, in which head is the index of the location 26 | // to which to write the next incoming character and tail is the index of the 27 | // location from which to read. 28 | #define SERIAL_BUFFER_SIZE 128 29 | 30 | class RingBuffer 31 | { 32 | public: 33 | volatile uint8_t _aucBuffer[SERIAL_BUFFER_SIZE]; 34 | volatile int _iHead; 35 | volatile int _iTail; 36 | 37 | public: 38 | RingBuffer(void); 39 | void store_char(uint8_t c); 40 | }; 41 | 42 | #endif /* _RING_BUFFER_ */ 43 | -------------------------------------------------------------------------------- /cores/arduino/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 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 server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print 26 | { 27 | public: 28 | virtual void begin() = 0; 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /cores/arduino/Tone.cpp: -------------------------------------------------------------------------------- 1 | /* Tone.cpp 2 | 3 | A Tone Generator Library 4 | 5 | Written by Brett Hagman 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 | #include "Arduino.h" 23 | 24 | uint8_t g_lastPin = NUM_DIGITAL_PINS; 25 | 26 | // frequency (in hertz) and duration (in milliseconds). 27 | 28 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) 29 | { 30 | 31 | if ((g_lastPin == NUM_DIGITAL_PINS) || (g_lastPin == _pin)) 32 | { 33 | TimerPinInit(_pin, frequency, duration); 34 | g_lastPin = _pin; 35 | } 36 | } 37 | 38 | void noTone(uint8_t _pin) 39 | { 40 | TimerPinDeinit(_pin); 41 | digitalWrite((uint32_t)_pin, 0); 42 | g_lastPin = NUM_DIGITAL_PINS; 43 | } 44 | -------------------------------------------------------------------------------- /cores/arduino/Tone.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_TONE_ 20 | #define _WIRING_TONE_ 21 | 22 | #ifdef __cplusplus 23 | /* 24 | * \brief Generate a tone to a pin. 25 | * 26 | * \param _pin 27 | * \param frequency Tone frequency (in hertz) 28 | * \param duration Tone duration (in milliseconds) 29 | */ 30 | extern void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); 31 | 32 | /* 33 | * \brief Stop tone generation on pin. 34 | * 35 | * \param _pin 36 | */ 37 | extern void noTone(uint8_t _pin); 38 | 39 | #endif 40 | 41 | #endif /* _WIRING_TONE_ */ 42 | -------------------------------------------------------------------------------- /cores/arduino/WInterrupts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "WInterrupts.h" 20 | #include "Arduino.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode) 28 | { 29 | 30 | //not a valid pin 31 | if (pin > NUM_DIGITAL_PINS) 32 | { 33 | return; 34 | } 35 | PinName p = digitalPinToPinName(pin); 36 | GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(p)); 37 | #if defined(STM8Sxx) 38 | EXTI_Sensitivity_TypeDef it_mode; 39 | switch (mode) 40 | { 41 | 42 | case CHANGE: 43 | it_mode = EXTI_SENSITIVITY_RISE_FALL; 44 | break; 45 | 46 | case FALLING: 47 | it_mode = EXTI_SENSITIVITY_FALL_ONLY; 48 | break; 49 | 50 | case LOW: 51 | it_mode = EXTI_SENSITIVITY_FALL_LOW; 52 | break; 53 | 54 | case RISING: 55 | case HIGH: 56 | it_mode = EXTI_SENSITIVITY_RISE_ONLY; 57 | break; 58 | 59 | default: 60 | it_mode = EXTI_SENSITIVITY_RISE_ONLY; 61 | break; 62 | } 63 | 64 | #elif defined(STM8Lxx) 65 | 66 | EXTI_Trigger_TypeDef it_mode; 67 | switch (mode) 68 | { 69 | 70 | case CHANGE: 71 | it_mode = EXTI_Trigger_Rising_Falling; 72 | break; 73 | 74 | case FALLING: 75 | it_mode = EXTI_Trigger_Falling; 76 | break; 77 | 78 | case LOW: 79 | it_mode = EXTI_Trigger_Falling_Low; 80 | break; 81 | 82 | case RISING: 83 | case HIGH: 84 | it_mode = EXTI_Trigger_Rising; 85 | break; 86 | 87 | default: 88 | it_mode = EXTI_Trigger_Rising; 89 | break; 90 | } 91 | 92 | #endif 93 | stm8_interrupt_enable(port, STM_GPIO_PIN(p), callback, it_mode); 94 | } 95 | 96 | void detachInterrupt(uint32_t pin) 97 | { 98 | //not a valid pin 99 | if (pin > NUM_DIGITAL_PINS) 100 | { 101 | return; 102 | } 103 | PinName p = digitalPinToPinName(pin); 104 | GPIO_TypeDef *port = get_GPIO_Port(STM_PORT(p)); 105 | stm8_interrupt_disable(port, STM_GPIO_PIN(p)); 106 | } 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | -------------------------------------------------------------------------------- /cores/arduino/WInterrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_INTERRUPTS_ 20 | #define _WIRING_INTERRUPTS_ 21 | 22 | #include "Arduino.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode); 30 | 31 | void detachInterrupt(uint32_t pin); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* _WIRING_INTERRUPTS_ */ 38 | -------------------------------------------------------------------------------- /cores/arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | extern "C" 20 | { 21 | #include "stdlib.h" 22 | #include "stdint.h" 23 | } 24 | #include "WMath.h" 25 | 26 | extern void randomSeed(uint32_t dwSeed) 27 | { 28 | if (dwSeed != 0) 29 | { 30 | srand(dwSeed); 31 | } 32 | } 33 | 34 | extern long random(long howbig) 35 | { 36 | if (howbig == 0) 37 | { 38 | return 0; 39 | } 40 | 41 | return rand() % howbig; 42 | } 43 | 44 | extern long random(long howsmall, long howbig) 45 | { 46 | if (howsmall >= howbig) 47 | { 48 | return howsmall; 49 | } 50 | 51 | long diff = howbig - howsmall; 52 | 53 | return random(diff) + howsmall; 54 | } 55 | 56 | extern long map(long x, long in_min, long in_max, long out_min, long out_max) 57 | { 58 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 59 | } 60 | 61 | extern uint16_t makeWord(uint16_t w) 62 | { 63 | return w; 64 | } 65 | 66 | extern uint16_t makeWord(uint8_t h, uint8_t l) 67 | { 68 | return (h << 8) | l; 69 | } 70 | -------------------------------------------------------------------------------- /cores/arduino/WMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_MATH_ 20 | #define _WIRING_MATH_ 21 | 22 | extern long random(long); 23 | extern long random(long, long); 24 | extern void randomSeed(uint32_t dwSeed); 25 | extern long map(long, long, long, long, long); 26 | 27 | extern uint16_t makeWord(uint16_t w); 28 | extern uint16_t makeWord(uint8_t h, uint8_t l); 29 | 30 | #define word(...) makeWord(__VA_ARGS__) 31 | 32 | #endif /* _WIRING_MATH_ */ 33 | -------------------------------------------------------------------------------- /cores/arduino/abi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | #ifdef __CSMC__ 22 | #define __noreturn __attribute__((noreturn)) 23 | extern "C" __noreturn void __cxa_pure_virtual(void); 24 | extern "C" __noreturn void __cxa_deleted_virtual(void); 25 | #else 26 | extern "C" void __cxa_pure_virtual(void) __attribute__((__noreturn__)); 27 | extern "C" void __cxa_deleted_virtual(void) __attribute__((__noreturn__)); 28 | #endif 29 | 30 | void __cxa_pure_virtual(void) 31 | { 32 | // We might want to write some diagnostics to uart in this case 33 | //std::terminate(); 34 | while (1) 35 | ; 36 | } 37 | 38 | void __cxa_deleted_virtual(void) 39 | { 40 | // We might want to write some diagnostics to uart in this case 41 | //std::terminate(); 42 | while (1) 43 | ; 44 | } 45 | -------------------------------------------------------------------------------- /cores/arduino/avr/dtostrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | char *stm8_strdup(char *src) { 26 | char *str; 27 | char *p; 28 | size_t len = strlen(src); 29 | 30 | str = malloc(len + 1); 31 | if (str) { 32 | memcpy(str, src, len + 1); 33 | } 34 | return str; 35 | } 36 | 37 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout) 38 | { 39 | //Commented code is the original version 40 | /*char fmt[20]; 41 | sprintf(fmt, "%%%d.%df", width, prec); 42 | sprintf(sout, fmt, val); 43 | return sout;*/ 44 | 45 | // Handle negative numbers 46 | unsigned int negative = 0; 47 | if (val < 0.0) 48 | { 49 | negative = 1; 50 | val = -val; 51 | } 52 | 53 | // Round correctly so that print(1.999, 2) prints as "2.00" 54 | double rounding = 0.5; 55 | int i; 56 | for (i = 0; i < prec; ++i) 57 | rounding /= 10.0; 58 | 59 | val += rounding; 60 | 61 | // Extract the integer part of the number 62 | unsigned long int_part = (unsigned long)val; 63 | double remainder = val - (double)int_part; 64 | 65 | if (negative) 66 | int_part = -int_part; 67 | 68 | // Extract digits from the remainder 69 | unsigned long dec_part = 0; 70 | double decade = 1.0; 71 | for (i = 0; i < prec; i++) 72 | decade *= 10.0; 73 | remainder *= decade; 74 | dec_part = (unsigned long)remainder; 75 | 76 | sprintf(sout, "%ld.%ld", int_part, dec_part); 77 | 78 | // Handle minimum field width of the output string 79 | // width is signed value, negative for left adjustment. 80 | // Range -128,127 81 | char fmt[129] = ""; 82 | unsigned int w = width; 83 | if (width < 0) { 84 | negative = 1; 85 | w = -width; 86 | } else { 87 | negative = 0; 88 | } 89 | 90 | if(strlen(sout) < w) { 91 | memset(fmt, ' ', 128); 92 | fmt[w-strlen(sout)] = '\0'; 93 | if(negative == 0) { 94 | char *tmp = stm8_strdup(sout); 95 | strcpy(sout,fmt); 96 | strcat(sout, tmp); 97 | free(tmp); 98 | } else { 99 | // left adjustment 100 | strcat(sout, fmt); 101 | } 102 | } 103 | 104 | return sout; 105 | } 106 | -------------------------------------------------------------------------------- /cores/arduino/avr/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2013 Arduino. All rights reserved. 4 | Written by Cristian Maglie 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | #ifndef __DTOSTRF_H_ 21 | #define __DTOSTRF_H_ 1 22 | 23 | #ifdef __cplusplus 24 | extern "C" 25 | { 26 | #endif 27 | 28 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /cores/arduino/board.c: -------------------------------------------------------------------------------- 1 | #include "board.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C" 5 | { 6 | #endif 7 | 8 | void __libc_init_array(void); 9 | 10 | void init(void) 11 | { 12 | hw_config_init(); 13 | } 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | -------------------------------------------------------------------------------- /cores/arduino/board.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOARD_H_ 2 | #define _BOARD_H_ 3 | 4 | /* 5 | * Core and peripherals registers definitions 6 | */ 7 | #include "interrupt.h" 8 | #ifdef __cplusplus 9 | extern "C"{ 10 | #endif // __cplusplus 11 | #include "analog.h" 12 | #include "clock.h" 13 | #include "digital_io.h" 14 | #include "hw_config.h" 15 | #include "spi_com.h" 16 | #include "stm8_eeprom.h" 17 | #include "timer.h" 18 | #include "twi.h" 19 | #include "uart.h" 20 | #include "stm8_it.h" 21 | 22 | void init( void ) ; 23 | #ifdef __cplusplus 24 | } 25 | #endif // __cplusplus 26 | #endif /* _BOARD_H_ */ 27 | -------------------------------------------------------------------------------- /cores/arduino/hooks.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | /** 19 | * Empty yield() hook. 20 | * 21 | * This function is intended to be used by library writers to build 22 | * libraries or sketches that supports cooperative threads. 23 | * 24 | * Its defined as a weak symbol and it can be redefined to implement a 25 | * real cooperative scheduler. 26 | */ 27 | 28 | 29 | #pragma weak yield 30 | void yield(void){ 31 | __asm("NOP"); 32 | } 33 | 34 | 35 | /** 36 | * SysTick hook 37 | * 38 | * This function is called from SysTick handler, before the default 39 | * handler provided by Arduino. 40 | */ 41 | static int __false() 42 | { 43 | // Return false 44 | return 0; 45 | } 46 | 47 | #ifdef __CSMC__ 48 | int sysTickHook(void); 49 | #pragma sysTickHook = __false 50 | #else 51 | int sysTickHook(void) __attribute__((weak, alias("__false"))); 52 | #endif 53 | 54 | /** 55 | * SVC hook 56 | * PendSV hook 57 | * 58 | * These functions are called from SVC handler, and PensSV handler. 59 | * Default action is halting. 60 | */ 61 | static void __halt() 62 | { 63 | // Halts 64 | while (1) 65 | ; 66 | } 67 | 68 | #ifdef __CSMC__ 69 | void svcHook(void); 70 | #pragma weak svcHook = __halt 71 | void pendSVHook(void); 72 | #pragma weak pendSVHook = __halt 73 | #else 74 | void svcHook(void) __attribute__((weak, alias("__halt"))); 75 | void pendSVHook(void) __attribute__((weak, alias("__halt"))); 76 | #endif -------------------------------------------------------------------------------- /cores/arduino/itoa.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _ITOA_ 20 | #define _ITOA_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif // __cplusplus 26 | 27 | #if 0 28 | 29 | extern void itoa( int n, char s[] ) ; 30 | 31 | #else 32 | 33 | extern char *itoa(int value, char *string, int radix); 34 | extern char *ltoa(long value, char *string, int radix); 35 | #if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 9 || \ 36 | (__GNUC_MINOR__ == 9 && __GNUC_PATCHLEVEL__ > 2))) 37 | extern char *utoa(unsigned value, char *string, int radix); 38 | #else 39 | extern char *utoa(unsigned long value, char *string, int radix); 40 | #endif 41 | extern char *ultoa(unsigned long value, char *string, int radix); 42 | #endif /* 0 */ 43 | 44 | #ifdef __cplusplus 45 | } // extern "C" 46 | #endif // __cplusplus 47 | 48 | #endif // _ITOA_ 49 | -------------------------------------------------------------------------------- /cores/arduino/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - Main loop for Arduino sketches 3 | Copyright (c) 2005-2013 Arduino Team. 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 | #define ARDUINO_MAIN 21 | #include "Arduino.h" 22 | 23 | // Weak empty variant initialization function. 24 | // May be redefined by variant files. 25 | 26 | #ifdef __CSMC__ 27 | #pragma weak initVariant 28 | #else 29 | void __weak initVariant(); 30 | #endif 31 | 32 | void initVariant() 33 | { 34 | } 35 | 36 | /* 37 | * \brief Main entry point of Arduino application 38 | */ 39 | int main(void) 40 | { 41 | initVariant(); 42 | 43 | init(); 44 | 45 | setup(); 46 | 47 | for (;;) 48 | { 49 | 50 | loop(); 51 | if (&serialEventRun) 52 | serialEventRun(); 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /cores/arduino/new.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | void *operator new(size_t size) 22 | { 23 | return malloc(size); 24 | } 25 | 26 | void *operator new[](size_t size) 27 | { 28 | return malloc(size); 29 | } 30 | 31 | void operator delete(void *ptr) 32 | { 33 | free(ptr); 34 | } 35 | 36 | void operator delete[](void *ptr) 37 | { 38 | free(ptr); 39 | } 40 | 41 | void operator delete(void *ptr, size_t /*size*/) 42 | { 43 | free(ptr); 44 | } 45 | 46 | void operator delete[](void *ptr, size_t /*size*/) 47 | { 48 | free(ptr); 49 | } -------------------------------------------------------------------------------- /cores/arduino/pins_arduino.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "pins_arduino.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | #ifdef __CSMC__ 27 | #pragma weak pinNametoDigitalPin 28 | uint32_t pinNametoDigitalPin(PinName p) 29 | #else 30 | WEAK uint32_t pinNametoDigitalPin(PinName p) 31 | #endif 32 | { 33 | uint32_t i = NC; 34 | if (STM_VALID_PINNAME(p)) 35 | { 36 | for (i = 0; i < NUM_DIGITAL_PINS; i++) 37 | { 38 | if (digitalPin[i] == p) 39 | break; 40 | } 41 | } 42 | return i; 43 | } 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PeripheralPins.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2014, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | 31 | #ifndef _PERIPHERALPINS_H 32 | #define _PERIPHERALPINS_H 33 | 34 | #include "pinmap.h" 35 | #if defined(STM8Lxx) 36 | #include "PinAF_STM8Lxx.h" 37 | #endif 38 | 39 | //*** ADC *** 40 | extern const PinMap PinMap_ADC[]; 41 | 42 | //*** I2C *** 43 | extern const PinMap PinMap_I2C_SDA[]; 44 | extern const PinMap PinMap_I2C_SCL[]; 45 | 46 | //*** PWM *** 47 | extern const PinMap PinMap_PWM[]; 48 | extern const PinMap PinMap_UART_TX[]; 49 | extern const PinMap PinMap_UART_RX[]; 50 | 51 | //*** SPI *** 52 | extern const PinMap PinMap_SPI_MOSI[]; 53 | extern const PinMap PinMap_SPI_MISO[]; 54 | extern const PinMap PinMap_SPI_SCLK[]; 55 | extern const PinMap PinMap_SPI_SSEL[]; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PinConfigured.c: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2017, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | #include "PinConfigured.h" 31 | 32 | bool is_pin_configured(PinName pin, uint32_t *map) 33 | { 34 | uint32_t index = PINCONF_INDEX(pin); 35 | return PINCONF_VAL(pin, map[index]); 36 | } 37 | 38 | void set_pin_configured(PinName pin, uint32_t *map) 39 | { 40 | uint32_t index = PINCONF_INDEX(pin); 41 | map[index] = map[index] | PINCONF_BIT(pin); 42 | } 43 | 44 | void reset_pin_configured(PinName pin, uint32_t *map) 45 | { 46 | uint32_t index = PINCONF_INDEX(pin); 47 | map[index] = map[index] & (~PINCONF_BIT(pin)); 48 | } 49 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PinConfigured.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2017, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | #ifndef _PINCONFIGURED_H 31 | #define _PINCONFIGURED_H 32 | 33 | #include "Arduino.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif 39 | 40 | #define PINCONF_INDEX(X) (STM_PORT(X) - FirstPort) 41 | 42 | #define PINCONF_MASK 0x01 43 | #define PINCONF_SHIFT(X) (STM_PIN(X)) 44 | #define PINCONF_BIT(X) (PINCONF_MASK << PINCONF_SHIFT(X)) 45 | 46 | #define PINCONF_VAL(X, Y) ((Y >> PINCONF_SHIFT(X)) & PINCONF_MASK) 47 | 48 | bool is_pin_configured(PinName pin, uint32_t *map); 49 | void set_pin_configured(PinName pin, uint32_t *map); 50 | void reset_pin_configured(PinName pin, uint32_t *map); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PinNames.h: -------------------------------------------------------------------------------- 1 | #ifndef _PINNAMES_H 2 | #define _PINNAMES_H 3 | 4 | #include "PinNamesTypes.h" 5 | #include "PortNames.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | typedef enum 13 | { 14 | PA_0 = (PortA << 4) + 0x00, 15 | PA_1 = (PortA << 4) + 0x01, 16 | PA_2 = (PortA << 4) + 0x02, 17 | PA_3 = (PortA << 4) + 0x03, 18 | PA_4 = (PortA << 4) + 0x04, 19 | PA_5 = (PortA << 4) + 0x05, 20 | PA_6 = (PortA << 4) + 0x06, 21 | PA_7 = (PortA << 4) + 0x07, 22 | 23 | PB_0 = (PortB << 4) + 0x00, 24 | PB_1 = (PortB << 4) + 0x01, 25 | PB_2 = (PortB << 4) + 0x02, 26 | PB_3 = (PortB << 4) + 0x03, 27 | PB_4 = (PortB << 4) + 0x04, 28 | PB_5 = (PortB << 4) + 0x05, 29 | PB_6 = (PortB << 4) + 0x06, 30 | PB_7 = (PortB << 4) + 0x07, 31 | 32 | #if defined (GPIOC_BaseAddress) || defined(GPIOC_BASE) 33 | PC_0 = (PortC << 4) + 0x00, 34 | PC_1 = (PortC << 4) + 0x01, 35 | PC_2 = (PortC << 4) + 0x02, 36 | PC_3 = (PortC << 4) + 0x03, 37 | PC_4 = (PortC << 4) + 0x04, 38 | PC_5 = (PortC << 4) + 0x05, 39 | PC_6 = (PortC << 4) + 0x06, 40 | PC_7 = (PortC << 4) + 0x07, 41 | #endif 42 | #if defined GPIOD_BaseAddress || defined(GPIOD_BASE) 43 | PD_0 = (PortD << 4) + 0x00, 44 | PD_1 = (PortD << 4) + 0x01, 45 | PD_2 = (PortD << 4) + 0x02, 46 | PD_3 = (PortD << 4) + 0x03, 47 | PD_4 = (PortD << 4) + 0x04, 48 | PD_5 = (PortD << 4) + 0x05, 49 | PD_6 = (PortD << 4) + 0x06, 50 | PD_7 = (PortD << 4) + 0x07, 51 | #endif 52 | #if defined GPIOE_BaseAddress || defined(GPIOE_BASE) 53 | PE_0 = (PortE << 4) + 0x00, 54 | PE_1 = (PortE << 4) + 0x01, 55 | PE_2 = (PortE << 4) + 0x02, 56 | PE_3 = (PortE << 4) + 0x03, 57 | PE_4 = (PortE << 4) + 0x04, 58 | PE_5 = (PortE << 4) + 0x05, 59 | PE_6 = (PortE << 4) + 0x06, 60 | PE_7 = (PortE << 4) + 0x07, 61 | #endif 62 | #if defined GPIOF_BaseAddress || defined(GPIOF_BASE) 63 | PF_0 = (PortF << 4) + 0x00, 64 | PF_1 = (PortF << 4) + 0x01, 65 | PF_2 = (PortF << 4) + 0x02, 66 | PF_3 = (PortF << 4) + 0x03, 67 | PF_4 = (PortF << 4) + 0x04, 68 | PF_5 = (PortF << 4) + 0x05, 69 | PF_6 = (PortF << 4) + 0x06, 70 | PF_7 = (PortF << 4) + 0x07, 71 | #endif 72 | #if defined GPIOG_BaseAddress || defined(GPIOG_BASE) 73 | PG_0 = (PortG << 4) + 0x00, 74 | PG_1 = (PortG << 4) + 0x01, 75 | PG_2 = (PortG << 4) + 0x02, 76 | PG_3 = (PortG << 4) + 0x03, 77 | PG_4 = (PortG << 4) + 0x04, 78 | PG_5 = (PortG << 4) + 0x05, 79 | PG_6 = (PortG << 4) + 0x06, 80 | PG_7 = (PortG << 4) + 0x07, 81 | #endif 82 | #if defined GPIOH_BaseAddress || defined(GPIOH_BASE) 83 | PH_0 = (PortH << 4) + 0x00, 84 | PH_1 = (PortH << 4) + 0x01, 85 | PH_2 = (PortH << 4) + 0x02, 86 | PH_3 = (PortH << 4) + 0x03, 87 | PH_4 = (PortH << 4) + 0x04, 88 | PH_5 = (PortH << 4) + 0x05, 89 | PH_6 = (PortH << 4) + 0x06, 90 | PH_7 = (PortH << 4) + 0x07, 91 | #endif 92 | #if defined GPIOI_BaseAddress || defined(GPIOI_BASE) 93 | PI_0 = (PortI << 4) + 0x00, 94 | #endif 95 | //NOT connecter 96 | NC = (int)0xFF 97 | } PinName; 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PortNames.c: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2017, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | #include "PortNames.h" 31 | #include "stm8_def.h" 32 | 33 | GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) 34 | { 35 | GPIO_TypeDef *gpioPort = 0; 36 | switch (port_idx) 37 | { 38 | case PortA: 39 | gpioPort = GPIOA; 40 | break; 41 | case PortB: 42 | gpioPort = GPIOB; 43 | break; 44 | 45 | #if defined(GPIOC_BaseAddress) || defined(GPIOC_BASE) 46 | case PortC: 47 | gpioPort = GPIOC; 48 | break; 49 | #endif 50 | #if defined(GPIOD_BaseAddress) || defined(GPIOD_BASE) 51 | case PortD: 52 | gpioPort = GPIOD; 53 | break; 54 | #endif 55 | #if defined(GPIOE_BaseAddress) || defined(GPIOE_BASE) 56 | case PortE: 57 | gpioPort = GPIOE; 58 | break; 59 | #endif 60 | #if defined(GPIOF_BaseAddress) || defined(GPIOF_BASE) 61 | case PortF: 62 | gpioPort = GPIOF; 63 | break; 64 | #endif 65 | #if defined(GPIOG_BaseAddress) || defined(GPIOG_BASE) 66 | case PortG: 67 | gpioPort = GPIOG; 68 | break; 69 | #endif 70 | #if defined(GPIOH_BaseAddress) || defined(GPIOH_BASE) 71 | case PortH: 72 | gpioPort = GPIOH; 73 | break; 74 | #endif 75 | #if defined(GPIOI_BaseAddress) || defined(GPIOI_BASE) 76 | case PortI: 77 | gpioPort = GPIOI; 78 | break; 79 | #endif 80 | default: 81 | // wrong port number 82 | //TBD: error management 83 | gpioPort = 0; 84 | break; 85 | } 86 | return gpioPort; 87 | } 88 | -------------------------------------------------------------------------------- /cores/arduino/stm8/PortNames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2016, STMicroelectronics 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 15 | * may be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ******************************************************************************* 29 | */ 30 | 31 | #ifndef _PORTNAMES_H 32 | #define _PORTNAMES_H 33 | 34 | #include "stm8_def.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" 38 | { 39 | #endif 40 | 41 | typedef enum 42 | { 43 | FirstPort = 0x00, 44 | PortA = FirstPort, 45 | PortB, 46 | #if defined(GPIOC_BaseAddress) || defined(GPIOC_BASE) 47 | PortC, 48 | #endif 49 | #if defined(GPIOD_BaseAddress) || defined(GPIOD_BASE) 50 | PortD, 51 | #endif 52 | #if defined(GPIOE_BaseAddress) || defined(GPIOE_BASE) 53 | PortE, 54 | #endif 55 | #if defined(GPIOF_BaseAddress) || defined(GPIOF_BASE) 56 | PortF, 57 | #endif 58 | #if defined(GPIOG_BaseAddress) || defined(GPIOG_BASE) 59 | PortG, 60 | #endif 61 | #if defined(GPIOH_BaseAddress) || defined(GPIOH_BASE) 62 | PortH, 63 | #endif 64 | #if defined(GPIOI_BaseAddress) || defined(GPIOI_BASE) 65 | PortI, 66 | #endif 67 | PortZ, 68 | LastPort = PortZ - 1 69 | } PortName; 70 | 71 | #define MAX_NB_PORT (LastPort - FirstPort + 1) 72 | 73 | GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx); 74 | GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | #endif 80 | -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_adc.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \ 2 | defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x) 3 | #include "stm8s_adc1.c" 4 | #endif 5 | 6 | #if defined(STM8S208) || defined(STM8S207) || defined (STM8S007) || defined (STM8AF52Ax) ||\ 7 | defined (STM8AF62Ax) 8 | #include "stm8s_adc2.c" 9 | #endif 10 | 11 | #if defined (STM8L15X_MD) || defined (STM8L15X_MDP) || defined (STM8L15X_HD) || defined (STM8L15X_LD) \ 12 | || defined (STM8L05X_LD_VL) || defined (STM8L05X_MD_VL) || defined (STM8L05X_HD_VL) || defined (STM8AL31_L_MD) 13 | #include "stm8l15x_adc.c" 14 | #endif 15 | -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_aes.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_aes.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_awu.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_awu.c" 3 | #endif 4 | -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_beep.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_beep.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_beep.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_can.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8S208) || defined (STM8AF52Ax) 2 | #include "stm8s_can.c" 3 | #endif /* (STM8S208) || (STM8AF52Ax) */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_clk.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_clk.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_clk.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_comp.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_comp.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_dac.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_dac.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_dma.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_dma.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_exti.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_exti.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_exti.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_flash.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_flash.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_flash.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_gpio.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_gpio.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_gpio.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_i2c.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_i2c.c" 3 | #elif defined (STM8L15X_MD) || defined (STM8L15X_MDP) || defined (STM8L15X_HD) || defined (STM8L15X_LD) \ 4 | || defined (STM8L05X_LD_VL) || defined (STM8L05X_MD_VL) || defined (STM8L05X_HD_VL) || defined (STM8AL31_L_MD) 5 | #include "stm8l15x_i2c.c" 6 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_irtim.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_irtim.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_itc.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_itc.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_itc.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_iwdg.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_iwdg.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_iwdg.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_lcd.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_lcd.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_pwr.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_pwr.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_rst.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_rst.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_rst.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_rtc.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_rtc.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_spi.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_spi.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_spi.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_syscfg.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_syscfg.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim1.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Sxx) 2 | #include "stm8s_tim1.c" 3 | #elif defined (STM8Lxx) 4 | #include "stm8l15x_tim1.c" 5 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim2.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8Sxx) 2 | #if !defined(STM8S903) || !defined(STM8AF622x) 3 | #include "stm8s_tim2.c" 4 | #endif 5 | #endif /* (STM8S903) || (STM8AF622x) */ 6 | #if defined(STM8Lxx) 7 | #include "stm8l15x_tim2.c" 8 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim3.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 2 | defined(STM8S005) || defined(STM8AF52Ax) || defined(STM8AF62Ax) || defined(STM8AF626x) 3 | #include "stm8s_tim3.c" 4 | #endif /* (STM8S208) ||defined(STM8S207) || defined(STM8S007) ||defined(STM8S105) */ 5 | #if defined(STM8Lxx) 6 | #include "stm8l15x_tim3.c" 7 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim4.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8Sxx) 2 | #if !defined(STM8S903) || !defined(STM8AF622x) 3 | #include "stm8s_tim4.c" 4 | #endif /* (STM8S903) || (STM8AF622x) */ 5 | #endif 6 | #if defined(STM8Lxx) 7 | #include "stm8l15x_tim4.c" 8 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim5.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8S903) || defined(STM8AF622x) 2 | #include "stm8s_tim5.c" 3 | #endif /* (STM8S903) || (STM8AF622x) */ 4 | #if defined(STM8Lxx) 5 | #include "stm8l15x_tim5.c" 6 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_tim6.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8S903) || defined(STM8AF622x) 2 | #include "stm8s_tim6.c" 3 | #endif /* (STM8S903) || (STM8AF622x) */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_uart1.c: -------------------------------------------------------------------------------- 1 | #if !defined(NO_HWSERIAL) 2 | #if defined(STM8S208) ||defined(STM8S207) || defined(STM8S007) ||defined(STM8S103) ||\ 3 | defined(STM8S003) ||defined(STM8S001) || defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 4 | #include "stm8s_uart1.c" 5 | #endif /* (STM8S208) || (STM8S207) || (STM8S103) || (STM8S001) || (STM8S903) || (STM8AF52Ax) || (STM8AF62Ax) */ 6 | #endif /* !NO_HWSERIAL */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_uart2.c: -------------------------------------------------------------------------------- 1 | #if !defined(NO_HWSERIAL) 2 | #if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x) 3 | #include "stm8s_uart2.c" 4 | #endif 5 | #endif /* !NO_HWSERIAL */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_uart3.c: -------------------------------------------------------------------------------- 1 | #if !defined(NO_HWSERIAL) 2 | #if defined(STM8S208) ||defined(STM8S207) || defined(STM8S007) || defined (STM8AF52Ax) ||\ 3 | defined (STM8AF62Ax) 4 | #include "stm8s_uart3.c" 5 | #endif 6 | #endif /* !NO_HWSERIAL */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_uart4.c: -------------------------------------------------------------------------------- 1 | #if !defined(NO_HWSERIAL) 2 | #if defined(STM8AF622x) 3 | #include "stm8s_uart4.c" 4 | #endif 5 | #endif /* !NO_HWSERIAL */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_usart.c: -------------------------------------------------------------------------------- 1 | #if !defined(NO_HWSERIAL) 2 | #if defined (STM8L15X_MD) || defined (STM8L15X_MDP) || defined (STM8L15X_HD) || defined (STM8L15X_LD) \ 3 | || defined (STM8L05X_LD_VL) || defined (STM8L05X_MD_VL) || defined (STM8L05X_HD_VL) || defined (STM8AL31_L_MD) 4 | #include "stm8l15x_usart.c" 5 | #endif 6 | #endif /* !NO_HWSERIAL */ -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_wfe.c: -------------------------------------------------------------------------------- 1 | #if defined (STM8Lxx) 2 | #include "stm8l15x_wfe.c" 3 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/STM8_StdPeriph_Driver/stm8xx_wwdg.c: -------------------------------------------------------------------------------- 1 | #if defined(STM8Sxx) 2 | #include "stm8s_wwdg.c" 3 | #endif 4 | #if defined(STM8Lxx) 5 | #include "stm8l15x_wwdg.c" 6 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/analog.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file analog.h 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for analog module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __ANALOG_H 40 | #define __ANALOG_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm8_def.h" 44 | #include "PeripheralPins.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" 48 | { 49 | #endif 50 | 51 | uint16_t adc_read_value(PinName pin); 52 | void pwm_start(PinName pin, uint32_t clock_freq, uint32_t period, uint32_t value, uint8_t do_init); 53 | void pwm_stop(PinName pin); 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __ANALOG_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /cores/arduino/stm8/clock.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file clock.h 4 | * @author MCD Application Team 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for clock.c module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __CLOCK_H 40 | #define __CLOCK_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm8_def.h" 44 | 45 | #ifdef __cplusplus 46 | extern "C" 47 | { 48 | #endif 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | /* Exported constants --------------------------------------------------------*/ 52 | /* Exported macro ------------------------------------------------------------*/ 53 | /* Exported functions ------------------------------------------------------- */ 54 | uint32_t GetCurrentMilli(void); 55 | uint32_t GetCurrentMicro(void); 56 | void InitDelayTimer(void); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __CLOCK_H */ 63 | 64 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 65 | -------------------------------------------------------------------------------- /cores/arduino/stm8/digital_io.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file digital_io.h 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for digital_io module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __DIGITAL_IO_H 40 | #define __DIGITAL_IO_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | //#include "stm8s.h" 44 | #include "stm8_def.h" 45 | #include "PeripheralPins.h" 46 | #ifdef __cplusplus 47 | extern "C" 48 | { 49 | #endif 50 | 51 | /* Exported types ------------------------------------------------------------*/ 52 | /* Exported constants --------------------------------------------------------*/ 53 | /* Exported macro ------------------------------------------------------------*/ 54 | #if defined(STM8Sxx) 55 | #define GPIO_Mode_In_FL_No_IT GPIO_MODE_IN_FL_NO_IT 56 | #define GPIO_Mode_In_PU_No_IT GPIO_MODE_IN_PU_NO_IT 57 | #define GPIO_Mode_Out_PP_Low_Slow GPIO_MODE_OUT_PP_LOW_SLOW 58 | #define GPIO_Mode_Out_PP_Low_Fast GPIO_MODE_OUT_PP_LOW_FAST 59 | #endif 60 | /* Exported functions ------------------------------------------------------- */ 61 | void digital_io_init(PinName pin, GPIO_Mode_TypeDef mode, uint32_t pull); 62 | void digital_io_write(GPIO_TypeDef *port, GPIO_Pin_TypeDef pin, uint32_t val); 63 | uint32_t digital_io_read(GPIO_TypeDef *port, GPIO_Pin_TypeDef pin); 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* __DIGITAL_IO_H */ 69 | 70 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 71 | -------------------------------------------------------------------------------- /cores/arduino/stm8/hw_config.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hw_config.c 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 7 | * @brief provide some hw interface for the Arduino interface 8 | * 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2016 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | #include "stm8_def.h" 40 | #include "hw_config.h" 41 | #include "clock.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" 45 | { 46 | #endif 47 | 48 | // NOTE: if function moved into variant.cpp a linker error occured! 49 | void SystemClock_Config(void) 50 | { 51 | #if defined(STM8Sxx) 52 | CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); 53 | #elif defined(STM8Lxx) 54 | CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); 55 | #else 56 | #error "Please select first the target STM8S/A/L device used in your application " 57 | #endif 58 | } 59 | 60 | /** 61 | * @brief This function performs the global init of the system (HAL, IOs...) 62 | * @param None 63 | * @retval None 64 | */ 65 | void hw_config_init(void) 66 | { 67 | // Configure the system clock 68 | SystemClock_Config(); 69 | 70 | InitDelayTimer(); 71 | } 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /cores/arduino/stm8/hw_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file hw_config.h 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for hw_config module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __HW_CONFIG_H 40 | #define __HW_CONFIG_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm8_def.h" 44 | #ifdef __cplusplus 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /* Exported types ------------------------------------------------------------*/ 50 | /* Exported constants --------------------------------------------------------*/ 51 | /* Exported macro ------------------------------------------------------------*/ 52 | /* Exported functions ------------------------------------------------------- */ 53 | void hw_config_init(void); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* __HW_CONFIG_H */ 60 | 61 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 62 | -------------------------------------------------------------------------------- /cores/arduino/stm8/interrupt.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file interrup.h 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for interrupt module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __INTERRUPT_H 40 | #define __INTERRUPT_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm8_def.h" 44 | #include "PinNames.h" 45 | #ifdef __cplusplus 46 | extern "C" 47 | { 48 | #endif 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | /* Exported constants --------------------------------------------------------*/ 52 | /* Exported macro ------------------------------------------------------------*/ 53 | /* Exported functions ------------------------------------------------------- */ 54 | #if defined(STM8Sxx) 55 | void stm8_interrupt_enable(GPIO_TypeDef *port, GPIO_Pin_TypeDef pin, 56 | void (*callback)(void), 57 | EXTI_Sensitivity_TypeDef mode); 58 | void GPIO_EXTI_Callback(EXTI_Port_TypeDef EXTI_port); 59 | #endif 60 | #if defined(STM8Lxx) 61 | void stm8_interrupt_enable(GPIO_TypeDef *port, GPIO_Pin_TypeDef pin, 62 | void (*callback)(void), 63 | EXTI_Trigger_TypeDef mode); 64 | void GPIO_EXTI_Callback(EXTI_IT_TypeDef EXTI_port_pin); 65 | #endif 66 | void stm8_interrupt_disable(GPIO_TypeDef *port, GPIO_Pin_TypeDef pin); 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __INTERRUPT_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /cores/arduino/stm8/pinmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | //Based on mbed-os/hal/mbed_pinmap_common.c 17 | 18 | #include "pinmap.h" 19 | 20 | void *pinmap_find_peripheral(PinName pin, const PinMap *map) 21 | { 22 | while (map->pin != NC) 23 | { 24 | if (map->pin == pin) 25 | return map->peripheral; 26 | map++; 27 | } 28 | return NP; 29 | } 30 | 31 | void *pinmap_peripheral(PinName pin, const PinMap *map) 32 | { 33 | void *peripheral = NP; 34 | 35 | if (pin != (PinName)NC) 36 | { 37 | peripheral = pinmap_find_peripheral(pin, map); 38 | } 39 | // else error("pinmap not found for peripheral"); 40 | return peripheral; 41 | } 42 | 43 | PinName pinmap_find_pin(void *peripheral, const PinMap *map) 44 | { 45 | while (map->peripheral != NP) 46 | { 47 | if (map->peripheral == peripheral) 48 | return map->pin; 49 | map++; 50 | } 51 | return NC; 52 | } 53 | 54 | PinName pinmap_pin(void *peripheral, const PinMap *map) 55 | { 56 | PinName pin = NC; 57 | 58 | if (peripheral != NP) 59 | { 60 | pin = pinmap_find_pin(peripheral, map); 61 | } 62 | // else error("pinmap not found for pin"); 63 | return pin; 64 | } 65 | 66 | uint32_t pinmap_find_function(PinName pin, const PinMap *map) 67 | { 68 | while (map->pin != NC) 69 | { 70 | if (map->pin == pin) 71 | return map->function; 72 | map++; 73 | } 74 | return (uint32_t)NC; 75 | } 76 | 77 | uint32_t pinmap_function(PinName pin, const PinMap *map) 78 | { 79 | uint32_t function = (uint32_t)NC; 80 | 81 | if (pin != (PinName)NC) 82 | { 83 | function = pinmap_find_function(pin, map); 84 | } 85 | // else error("pinmap not found for function"); 86 | return function; 87 | } 88 | 89 | bool pin_in_pinmap(PinName pin, const PinMap *map) 90 | { 91 | if (pin != (PinName)NC) 92 | { 93 | while (map->pin != NC) 94 | { 95 | if (map->pin == pin) 96 | return true; 97 | map++; 98 | } 99 | } 100 | return false; 101 | } 102 | 103 | // Merge peripherals 104 | void *pinmap_merge_peripheral(void *a, void *b) 105 | { 106 | // both are the same (inc both NP) 107 | if (a == b) 108 | return a; 109 | 110 | // one (or both) is not set 111 | if (a == NP) 112 | return b; 113 | if (b == NP) 114 | return a; 115 | 116 | // mis-match error case 117 | // error("pinmap mis-match"); 118 | return NP; 119 | } 120 | 121 | PinName pin_pinName(const PinMap *map) 122 | { 123 | if (map->pin != (PinName)NC) 124 | { 125 | return map->pin; 126 | } 127 | else 128 | { 129 | return (PinName)NC; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /cores/arduino/stm8/pinmap.h: -------------------------------------------------------------------------------- 1 | 2 | /** \addtogroup hal */ 3 | /** @{*/ 4 | /* mbed Microcontroller Library 5 | * Copyright (c) 2006-2013 ARM Limited 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | #ifndef _PINMAP_H 20 | #define _PINMAP_H 21 | 22 | #include "PinNames.h" 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" 28 | { 29 | #endif 30 | 31 | #define NP 0U 32 | 33 | typedef struct 34 | { 35 | PinName pin; 36 | void *peripheral; 37 | int function; 38 | } PinMap; 39 | 40 | bool pin_in_pinmap(PinName pin, const PinMap *map); 41 | void pin_function(PinName pin, int function); 42 | 43 | PinName pin_pinName(const PinMap *map); 44 | 45 | void *pinmap_find_peripheral(PinName pin, const PinMap *map); 46 | void *pinmap_peripheral(PinName pin, const PinMap *map); 47 | PinName pinmap_find_pin(void *peripheral, const PinMap *map); 48 | PinName pinmap_pin(void *peripheral, const PinMap *map); 49 | uint32_t pinmap_find_function(PinName pin, const PinMap *map); 50 | uint32_t pinmap_function(PinName pin, const PinMap *map); 51 | void *pinmap_merge_peripheral(void *a, void *b); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | 59 | /** @}*/ -------------------------------------------------------------------------------- /cores/arduino/stm8/stm8_def.c: -------------------------------------------------------------------------------- 1 | #include "stm8_def.h" 2 | 3 | #ifdef __cplusplus 4 | extern "C" 5 | { 6 | #endif 7 | 8 | #pragma weak _Error_Handler 9 | void _Error_Handler(const char *msg, int val) 10 | { 11 | while (1) 12 | { 13 | } 14 | } 15 | #ifdef __cplusplus 16 | } 17 | #endif -------------------------------------------------------------------------------- /cores/arduino/stm8/stm8_def.h: -------------------------------------------------------------------------------- 1 | #ifndef _STM8_DEF_ 2 | #define _STM8_DEF_ 3 | 4 | /** 5 | * @brief STM8 core version number 6 | */ 7 | #define STM8_CORE_VERSION_MAJOR (0x01U) /*!< [31:24] major version */ 8 | #define STM8_CORE_VERSION_MINOR (0x00U) /*!< [23:16] minor version */ 9 | #define STM8_CORE_VERSION_PATCH (0x00U) /*!< [15:8] patch version */ 10 | /* 11 | * Extra label for development: 12 | * 0: official release 13 | * [1-9]: release candidate 14 | * F[0-9]: development 15 | */ 16 | #define STM8_CORE_VERSION_EXTRA (0x00U) /*!< [7:0] extra version */ 17 | #define STM8_CORE_VERSION ((STM8_CORE_VERSION_MAJOR << 24U)\ 18 | |(STM8_CORE_VERSION_MINOR << 16U)\ 19 | |(STM8_CORE_VERSION_PATCH << 8U )\ 20 | |(STM8_CORE_VERSION_EXTRA)) 21 | 22 | #if defined(STM8Sxx) 23 | #include "stm8s.h" 24 | #elif defined(STM8Lxx) 25 | #include "stm8l15x.h" 26 | #else 27 | #error "Please select first the target STM8S/A/L device used in your application " 28 | #endif 29 | 30 | /* Here define some compatibility */ 31 | #if defined(STM8Sxx) 32 | #define AFIO_NONE 0 33 | #if defined(ADC2) 34 | #define ADCx ADC2 35 | #elif defined(ADC1) 36 | #define ADCx ADC1 37 | #else 38 | #error "Can't define ADCx" 39 | #endif 40 | #endif /* STM8Sxx */ 41 | 42 | #ifdef __cplusplus 43 | extern "C" 44 | { 45 | #endif 46 | void SystemClock_Config(void); 47 | void _Error_Handler(const char *, int); 48 | #define Error_Handler() _Error_Handler(__FILE__, __LINE__) 49 | 50 | #ifdef __cplusplus 51 | } // extern "C" 52 | #endif // __cplusplus 53 | 54 | #endif //_STM8_DEF_ 55 | -------------------------------------------------------------------------------- /cores/arduino/stm8/stm8_eeprom.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_eeprom.h 4 | * @author WI6LABS 5 | * @version V1.0.0 6 | * @date 16-September-2016 7 | * @brief Header for eeprom module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2016 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM8S_EEPROM_H 40 | #define __STM8S_EEPROM_H 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm8_def.h" 44 | 45 | #ifdef __cplusplus 46 | extern "C" 47 | { 48 | #endif 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | /* Exported constants --------------------------------------------------------*/ 52 | #if defined(STM8Sxx) 53 | #define E2END ((uint16_t)(FLASH_DATA_BLOCKS_NUMBER * FLASH_BLOCK_SIZE)) 54 | /* Exported macro ------------------------------------------------------------*/ 55 | /* Exported functions ------------------------------------------------------- */ 56 | uint8_t eeprom_read_byte(const uint16_t __p); 57 | void eeprom_write_byte(uint16_t __p, uint8_t __value); 58 | #endif 59 | #if defined(STM8Lxx) 60 | #define E2END ((uint16_t)(FLASH_DATA_EEPROM_BLOCKS_NUMBER * FLASH_BLOCK_SIZE)) 61 | /* Exported macro ------------------------------------------------------------*/ 62 | /* Exported functions ------------------------------------------------------- */ 63 | uint8_t eeprom_read_byte(const uint16_t __p); 64 | void eeprom_write_byte(uint16_t __p, uint8_t __value); 65 | #endif 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __EEPROM_H */ 71 | 72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /cores/arduino/syscalls_stm8.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /** 20 | * \file syscalls_sam3.c 21 | * 22 | * Implementation of newlib syscall. 23 | * 24 | */ 25 | 26 | /*---------------------------------------------------------------------------- 27 | * Headers 28 | *----------------------------------------------------------------------------*/ 29 | 30 | #include 31 | #include 32 | #if defined(__GNUC__) /* GCC CS3 */ 33 | #include 34 | #include 35 | #endif 36 | 37 | #include "Arduino.h" 38 | 39 | // Helper macro to mark unused parameters and prevent compiler warnings. 40 | // Appends _UNUSED to the variable name to prevent accidentally using them. 41 | #undef UNUSED 42 | #ifdef __GNUC__ 43 | #define UNUSED(x) x##_UNUSED __attribute__((__unused__)) 44 | #else 45 | #define UNUSED(x) x##_UNUSED 46 | #endif 47 | 48 | /*---------------------------------------------------------------------------- 49 | * Exported variables 50 | *----------------------------------------------------------------------------*/ 51 | 52 | #undef errno 53 | extern int errno; 54 | extern int _end; 55 | 56 | /*---------------------------------------------------------------------------- 57 | * Exported functions 58 | *----------------------------------------------------------------------------*/ 59 | extern void _exit(int status); 60 | extern void _kill(int pid, int sig); 61 | extern int _getpid(void); 62 | 63 | extern int link(UNUSED(char *cOld), UNUSED(char *cNew)) 64 | { 65 | return -1; 66 | } 67 | 68 | extern int _close(UNUSED(int file)) 69 | { 70 | return -1; 71 | } 72 | 73 | extern int _isatty(UNUSED(int file)) 74 | { 75 | return 1; 76 | } 77 | 78 | extern int _lseek(UNUSED(int file), UNUSED(int ptr), UNUSED(int dir)) 79 | { 80 | return 0; 81 | } 82 | 83 | extern int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len)) 84 | { 85 | return 0; 86 | } 87 | 88 | extern int __write(UNUSED(int file), char *ptr, int len) 89 | { 90 | int iIndex = 0; 91 | 92 | for (iIndex = 0; iIndex < len; iIndex++) 93 | { 94 | } 95 | return iIndex; 96 | } 97 | 98 | extern void _exit(int status) 99 | { 100 | printf("Exiting with status %d.\n", status); 101 | 102 | for (;;) 103 | ; 104 | } 105 | 106 | extern void _kill(UNUSED(int pid), UNUSED(int sig)) 107 | { 108 | return; 109 | } 110 | 111 | extern int _getpid(void) 112 | { 113 | return -1; 114 | } 115 | -------------------------------------------------------------------------------- /cores/arduino/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H 2 | #define __UTILS_H 3 | 4 | #include "avr/dtostrf.h" 5 | 6 | // Concatenate 2 strings 7 | #define CONCAT(s1, s2) (s1 s2) 8 | // Concatenate 2 strings separated by space 9 | #define CONCATS(s1, s2) (s1 " " s2) 10 | 11 | // Stringification 12 | #define xstr(s) str(s) 13 | #define str(s) #s 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /cores/arduino/wiring.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | Copyright (c) 2013 by Paul Stoffregen (delayMicroseconds) 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. 13 | See the GNU 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 _WIRING_H_ 21 | #define _WIRING_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "binary.h" 30 | #include "itoa.h" 31 | #include "utils.h" 32 | 33 | #include "wiring_analog.h" 34 | #include "wiring_constants.h" 35 | #include "wiring_digital.h" 36 | #include "wiring_pulse.h" 37 | #include "wiring_shift.h" 38 | #include "wiring_time.h" 39 | #include "WInterrupts.h" 40 | 41 | #include 42 | 43 | #ifdef __cplusplus 44 | #include "HardwareSerial.h" 45 | #include "Tone.h" 46 | #include "WCharacter.h" 47 | #include "WMath.h" 48 | #include "WString.h" 49 | #endif // __cplusplus 50 | 51 | #define clockCyclesPerMicrosecond() (F_CPU / 1000000L) 52 | #define clockCyclesToMicroseconds(a) (((a)*1000L) / (F_CPU / 1000L)) 53 | #define microsecondsToClockCycles(a) ((a) * (F_CPU / 1000000L)) 54 | 55 | #endif /* _WIRING_H_ */ 56 | -------------------------------------------------------------------------------- /cores/arduino/wiring_analog.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_ANALOG_ 20 | #define _WIRING_ANALOG_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | /* 28 | * \brief SAM3 products have only one reference for ADC 29 | */ 30 | typedef enum _eAnalogReference 31 | { 32 | AR_DEFAULT, 33 | } eAnalogReference; 34 | 35 | /* 36 | * \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). 37 | * This function is kept only for compatibility with existing AVR based API. 38 | * 39 | * \param ulMmode Should be set to AR_DEFAULT. 40 | */ 41 | extern void analogReference(eAnalogReference ulMode); 42 | 43 | /* 44 | * \brief Writes an analog value (PWM wave) to a pin. 45 | * 46 | * \param ulPin 47 | * \param ulValue 48 | */ 49 | extern void analogWrite(uint32_t ulPin, uint32_t ulValue); 50 | 51 | /* 52 | * \brief Reads the value from the specified analog pin. 53 | * 54 | * \param ulPin 55 | * 56 | * \return Read value from selected pin, if no error. 57 | */ 58 | extern uint32_t analogRead(uint32_t ulPin); 59 | 60 | /* 61 | * \brief Set the resolution of analogRead return values. Default is 10 bits (range from 0 to 1023). 62 | * 63 | * \param res 64 | */ 65 | extern void analogReadResolution(int res); 66 | 67 | /* 68 | * \brief Set the resolution of analogWrite parameters. Default is 8 bits (range from 0 to 255). 69 | * 70 | * \param res 71 | */ 72 | extern void analogWriteResolution(int res); 73 | 74 | extern void analogOutputInit(void); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* _WIRING_ANALOG_ */ 81 | -------------------------------------------------------------------------------- /cores/arduino/wiring_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_CONSTANTS_ 20 | #define _WIRING_CONSTANTS_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | 26 | #ifdef __CSMC__ 27 | #ifndef abs 28 | #define abs(x) ((x) > 0 ? (x) : -(x)) 29 | #endif // abs 30 | 31 | #ifndef min 32 | #define min(a, b) ((a) < (b) ? (a) : (b)) 33 | #endif // min 34 | 35 | #ifndef max 36 | #define max(a, b) ((a) > (b) ? (a) : (b)) 37 | #endif // max 38 | #else 39 | #include 40 | using std::max; 41 | using std::min; 42 | #endif 43 | #else // C 44 | #ifndef abs 45 | #define abs(x) ((x) > 0 ? (x) : -(x)) 46 | #endif // abs 47 | 48 | #ifndef min 49 | #define min(a, b) ((a) < (b) ? (a) : (b)) 50 | #endif // min 51 | 52 | #ifndef max 53 | #define max(a, b) ((a) > (b) ? (a) : (b)) 54 | #endif // max 55 | 56 | #endif // __cplusplus 57 | 58 | #define HIGH 0x1 59 | #define LOW 0x0 60 | 61 | #define INPUT 0x0 62 | #define OUTPUT 0x1 63 | #define INPUT_PULLUP 0x2 64 | #define INPUT_PULLDOWN 0x3 65 | 66 | #define PI 3.1415926535897932384626433832795 67 | #define HALF_PI 1.5707963267948966192313216916398 68 | #define TWO_PI 6.283185307179586476925286766559 69 | #define DEG_TO_RAD 0.017453292519943295769236907684886 70 | #define RAD_TO_DEG 57.295779513082320876798154814105 71 | #define EULER 2.718281828459045235360287471352 72 | 73 | #define SERIAL 0x0 74 | #define DISPLAY 0x1 75 | 76 | enum BitOrder 77 | { 78 | LSBFIRST = 0, 79 | MSBFIRST = 1 80 | }; 81 | 82 | // LOW 0 83 | // HIGH 1 84 | #define CHANGE 2 85 | #define FALLING 3 86 | #define RISING 4 87 | 88 | #define DEFAULT 1 89 | #define EXTERNAL 0 90 | 91 | #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) 92 | 93 | #define radians(deg) ((deg)*DEG_TO_RAD) 94 | #define degrees(rad) ((rad)*RAD_TO_DEG) 95 | #define sq(x) ((x) * (x)) 96 | 97 | #define interrupts() __enable_irq() 98 | #define noInterrupts() __disable_irq() 99 | 100 | #define lowByte(w) ((uint8_t)((w)&0xff)) 101 | #define highByte(w) ((uint8_t)((w) >> 8)) 102 | 103 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) 104 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) 105 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) 106 | #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) 107 | 108 | #define bit(b) (1UL << (b)) 109 | //macro added for compatibility 110 | #ifndef _BV 111 | #define _BV(bit) (1 << (bit)) 112 | #endif 113 | #ifndef cbi 114 | #define cbi(reg, bitmask) *reg &= ~bitmask 115 | #endif 116 | #ifndef sbi 117 | #define sbi(reg, bitmask) *reg |= bitmask 118 | #endif 119 | 120 | typedef unsigned int word; 121 | 122 | typedef bool boolean; 123 | 124 | typedef uint8_t byte; 125 | 126 | #endif /* _WIRING_CONSTANTS_ */ 127 | -------------------------------------------------------------------------------- /cores/arduino/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Arduino.h" 20 | #include "PinConfigured.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | //This is the list of the IOs configured 28 | uint32_t g_digPinConfigured[MAX_NB_PORT] = {0}; 29 | extern uint32_t g_anOutputPinConfigured[MAX_NB_PORT]; 30 | 31 | void pinMode(uint32_t ulPin, uint32_t ulMode) 32 | { 33 | PinName p = digitalPinToPinName(ulPin); 34 | 35 | if (p != NC) 36 | { 37 | // If the pin that support PWM or DAC output, we need to turn it off 38 | if (is_pin_configured(p, g_anOutputPinConfigured)) 39 | { 40 | #ifdef HAL_DAC_MODULE_ENABLED 41 | if (pin_in_pinmap(p, PinMap_DAC)) 42 | { 43 | dac_stop(p); 44 | } 45 | else 46 | #endif //HAL_DAC_MODULE_ENABLED 47 | if (pin_in_pinmap(p, PinMap_PWM)) 48 | { 49 | pwm_stop(p); 50 | } 51 | reset_pin_configured(p, g_anOutputPinConfigured); 52 | } 53 | 54 | switch (ulMode) 55 | { 56 | case INPUT: 57 | digital_io_init(p, GPIO_Mode_In_FL_No_IT, 0); 58 | break; 59 | case INPUT_PULLUP: 60 | digital_io_init(p, GPIO_Mode_In_PU_No_IT, 0); 61 | break; 62 | case INPUT_PULLDOWN: 63 | digital_io_init(p, GPIO_Mode_In_FL_No_IT, 0); 64 | break; 65 | case OUTPUT: 66 | digital_io_init(p, GPIO_Mode_Out_PP_Low_Fast, 0); 67 | break; 68 | default: 69 | break; 70 | } 71 | set_pin_configured(p, g_digPinConfigured); 72 | } 73 | } 74 | 75 | void digitalWrite(uint32_t ulPin, uint32_t ulVal) 76 | { 77 | PinName p = digitalPinToPinName(ulPin); 78 | if (p != NC) 79 | { 80 | if (is_pin_configured(p, g_digPinConfigured)) 81 | { 82 | digital_io_write(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p), ulVal); 83 | } 84 | } 85 | } 86 | 87 | int digitalRead(uint32_t ulPin) 88 | { 89 | uint8_t level = 0; 90 | PinName p = digitalPinToPinName(ulPin); 91 | if (p != NC) 92 | { 93 | if (is_pin_configured(p, g_digPinConfigured)) 94 | { 95 | level = digital_io_read(get_GPIO_Port(STM_PORT(p)), STM_GPIO_PIN(p)); 96 | } 97 | } 98 | return (level) ? HIGH : LOW; 99 | } 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | -------------------------------------------------------------------------------- /cores/arduino/wiring_digital.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_DIGITAL_ 20 | #define _WIRING_DIGITAL_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | /** 28 | * \brief Configures the specified pin to behave either as an input or an output. See the description of digital pins for details. 29 | * 30 | * \param ulPin The number of the pin whose mode you wish to set 31 | * \param ulMode Either INPUT or OUTPUT 32 | */ 33 | extern void pinMode(uint32_t dwPin, uint32_t dwMode); 34 | 35 | /** 36 | * \brief Write a HIGH or a LOW value to a digital pin. 37 | * 38 | * If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the 39 | * corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. 40 | * 41 | * If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal 42 | * 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup 43 | * resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely 44 | * cause. The remedy is to set the pin to an output with the pinMode() function. 45 | * 46 | * \note Digital pin PIN_LED is harder to use as a digital input than the other digital pins because it has an LED 47 | * and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up 48 | * resistor, it will hang at around 1.7 V instead of the expected 5V because the onboard LED and series resistor 49 | * pull the voltage level down, meaning it always returns LOW. If you must use pin PIN_LED as a digital input, use an 50 | * external pull down resistor. 51 | * 52 | * \param dwPin the pin number 53 | * \param dwVal HIGH or LOW 54 | */ 55 | extern void digitalWrite(uint32_t dwPin, uint32_t dwVal); 56 | 57 | /** 58 | * \brief Reads the value from a specified digital pin, either HIGH or LOW. 59 | * 60 | * \param ulPin The number of the digital pin you want to read (int) 61 | * 62 | * \return HIGH or LOW 63 | */ 64 | extern int digitalRead(uint32_t ulPin); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* _WIRING_DIGITAL_ */ 71 | -------------------------------------------------------------------------------- /cores/arduino/wiring_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef WiringPrivate_h 20 | #define WiringPrivate_h 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /cores/arduino/wiring_pulse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Arduino.h" 20 | 21 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 22 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 23 | * to 3 minutes in length, but must be called at least a few dozen microseconds 24 | * before the start of the pulse. 25 | * 26 | * ATTENTION: 27 | * This function relies on micros() so cannot be used in noInterrupt() context 28 | */ 29 | uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout) 30 | { 31 | // Cache the port and bit of the pin in order to speed up the 32 | // pulse width measuring loop and achieve finer resolution. 33 | // Calling digitalRead() instead yields much coarser resolution. 34 | uint32_t bit = digitalPinToBitMask(pin); 35 | __IO unsigned char *portIn = portInputRegister(digitalPinToPort(pin)); 36 | uint32_t stateMask = (state ? bit : 0); 37 | uint32_t startMicros = micros(); 38 | 39 | // wait for any previous pulse to end 40 | while ((*portIn & bit) == stateMask) 41 | { 42 | if (micros() - startMicros > timeout) 43 | return 0; 44 | } 45 | 46 | // wait for the pulse to start 47 | while ((*portIn & bit) != stateMask) 48 | { 49 | if (micros() - startMicros > timeout) 50 | return 0; 51 | } 52 | 53 | uint32_t start = micros(); 54 | // wait for the pulse to stop 55 | while ((*portIn & bit) == stateMask) 56 | { 57 | if (micros() - startMicros > timeout) 58 | return 0; 59 | } 60 | return (micros() - start); 61 | } 62 | 63 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 64 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 65 | * to 3 minutes in length, but must be called at least a few dozen microseconds 66 | * before the start of the pulse. 67 | * 68 | * ATTENTION: 69 | * This function relies on micros() so cannot be used in noInterrupt() context 70 | */ 71 | uint32_t pulseInLong(uint32_t pin, uint32_t state, uint32_t timeout) 72 | { 73 | return pulseIn(pin, state, timeout); 74 | } 75 | -------------------------------------------------------------------------------- /cores/arduino/wiring_pulse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_PULSE_ 20 | #define _WIRING_PULSE_ 21 | 22 | #ifdef __cplusplus 23 | /* 24 | * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH 25 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 26 | * to 3 minutes in length, but must be called at least a few dozen microseconds 27 | * before the start of the pulse. 28 | */ 29 | extern uint32_t pulseIn(uint32_t pin, uint32_t state, uint32_t timeout = 1000000L); 30 | extern uint32_t pulseInLong(uint32_t pin, uint32_t state, uint32_t timeout = 1000000L); 31 | #endif 32 | 33 | #endif /* _WIRING_PULSE_ */ 34 | -------------------------------------------------------------------------------- /cores/arduino/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Arduino.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | uint32_t shiftIn(uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder) 27 | { 28 | uint8_t value = 0; 29 | uint8_t i; 30 | 31 | for (i = 0; i < 8; ++i) 32 | { 33 | digitalWrite(ulClockPin, HIGH); 34 | 35 | if (ulBitOrder == LSBFIRST) 36 | { 37 | value |= digitalRead(ulDataPin) << i; 38 | } 39 | else 40 | { 41 | value |= digitalRead(ulDataPin) << (7 - i); 42 | } 43 | 44 | digitalWrite(ulClockPin, LOW); 45 | } 46 | 47 | return value; 48 | } 49 | 50 | void shiftOut(uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal) 51 | { 52 | uint8_t i; 53 | 54 | for (i = 0; i < 8; i++) 55 | { 56 | if (ulBitOrder == LSBFIRST) 57 | { 58 | digitalWrite(ulDataPin, !!(ulVal & (1 << i))); 59 | } 60 | else 61 | { 62 | digitalWrite(ulDataPin, !!(ulVal & (1 << (7 - i)))); 63 | } 64 | 65 | digitalWrite(ulClockPin, HIGH); 66 | digitalWrite(ulClockPin, LOW); 67 | } 68 | } 69 | 70 | #ifdef __cplusplus 71 | } // extern "C" 72 | #endif 73 | -------------------------------------------------------------------------------- /cores/arduino/wiring_shift.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_SHIFT_ 20 | #define _WIRING_SHIFT_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" 24 | { 25 | #endif 26 | 27 | /* 28 | * \brief 29 | */ 30 | extern uint32_t shiftIn(uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder); 31 | 32 | /* 33 | * \brief 34 | */ 35 | extern void shiftOut(uint32_t ulDataPin, uint32_t ulClockPin, uint32_t ulBitOrder, uint32_t ulVal); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* _WIRING_SHIFT_ */ 42 | -------------------------------------------------------------------------------- /cores/arduino/wiring_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Arduino.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | uint32_t millis(void) 27 | { 28 | // todo: ensure no interrupts 29 | return GetCurrentMilli(); 30 | } 31 | 32 | // Interrupt-compatible version of micros 33 | uint32_t micros(void) 34 | { 35 | return GetCurrentMicro(); 36 | } 37 | 38 | void delay(uint32_t ms) 39 | { 40 | if (ms == 0) 41 | return; 42 | uint32_t start = GetCurrentMilli(); 43 | do 44 | { 45 | yield(); 46 | } while (GetCurrentMilli() - start < ms); 47 | } 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /cores/arduino/wiring_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | Copyright (c) 2013 by Paul Stoffregen (delayMicroseconds) 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. 13 | See the GNU 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 _WIRING_TIME_H_ 21 | #define _WIRING_TIME_H_ 22 | 23 | #include "clock.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | /** 30 | * \brief Returns the number of milliseconds since the Arduino board began running the current program. 31 | * 32 | * This number will overflow (go back to zero), after approximately 50 days. 33 | * 34 | * \return Number of milliseconds since the program started (uint32_t) 35 | */ 36 | extern uint32_t millis(void); 37 | 38 | /** 39 | * \brief Returns the number of microseconds since the Arduino board began running the current program. 40 | * 41 | * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards 42 | * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is 43 | * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution 44 | * of eight microseconds. 45 | * 46 | * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. 47 | */ 48 | extern uint32_t micros(void); 49 | 50 | /** 51 | * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. 52 | * (There are 1000 milliseconds in a second.) 53 | * 54 | * \param dwMs the number of milliseconds to pause (uint32_t) 55 | */ 56 | extern void delay(uint32_t dwMs); 57 | 58 | /** 59 | * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. 60 | * 61 | * \param dwUs the number of microseconds to pause (uint32_t) 62 | */ 63 | #ifndef __CSMC__ 64 | static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); 65 | #endif 66 | static inline void delayMicroseconds(uint32_t usec) 67 | { 68 | uint32_t start = GetCurrentMicro(); 69 | 70 | while ((start + usec) > GetCurrentMicro()) 71 | ; 72 | } 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* _WIRING_TIME_H_ */ 79 | -------------------------------------------------------------------------------- /libraries/CapacitiveSensor-0.5.1/CapacitiveSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | CapacitiveSense.h v.04 - Capacitive Sensing Library for 'duino / Wiring 3 | https://github.com/PaulStoffregen/CapacitiveSensor 4 | http://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html 5 | http://playground.arduino.cc/Main/CapacitiveSensor 6 | Copyright (c) 2008 Paul Bagder All rights reserved. 7 | Version 05 by Paul Stoffregen - Support non-AVR board: Teensy 3.x, Arduino Due 8 | Version 04 by Paul Stoffregen - Arduino 1.0 compatibility, issue 146 fix 9 | vim: set ts=4: 10 | */ 11 | 12 | // ensure this library description is only included once 13 | #ifndef CapacitiveSensor_h 14 | #define CapacitiveSensor_h 15 | 16 | #include "Arduino.h" 17 | 18 | // library interface description 19 | class CapacitiveSensor 20 | { 21 | // user-accessible "public" interface 22 | public: 23 | // methods 24 | CapacitiveSensor(uint8_t sendPin, uint8_t receivePin); 25 | long capacitiveSensorRaw(uint8_t samples); 26 | long capacitiveSensor(uint8_t samples); 27 | void set_CS_Timeout_Millis(unsigned long timeout_millis); 28 | void reset_CS_AutoCal(); 29 | void set_CS_AutocaL_Millis(unsigned long autoCal_millis); 30 | // library-accessible "private" interface 31 | private: 32 | // variables 33 | int error; 34 | unsigned long leastTotal; 35 | unsigned int loopTimingFactor; 36 | unsigned long CS_Timeout_Millis; 37 | unsigned long CS_AutocaL_Millis; 38 | unsigned long lastCal; 39 | unsigned long total; 40 | //IO_REG_TYPE sBit; // send pin's ports and bitmask 41 | //volatile IO_REG_TYPE *sReg; 42 | //IO_REG_TYPE rBit; // receive pin's ports and bitmask 43 | //volatile IO_REG_TYPE *rReg; 44 | uint32_t rPin; 45 | uint32_t sPin; 46 | // methods 47 | int SenseOneCycle(void); 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libraries/CapacitiveSensor-0.5.1/README.md: -------------------------------------------------------------------------------- 1 | #CapacitiveSensor Library# 2 | 3 | CapacitiveSensor lets you create sensors that can detect touch or proximity. 4 | 5 | http://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html 6 | 7 | http://playground.arduino.cc/Main/CapacitiveSensor 8 | 9 | http://www.youtube.com/watch?v=BHQPqQ_5ulc 10 | 11 | CapacitiveSensor was originally written by Paul Badger and is now maintained by Paul Stoffregen. 12 | 13 | ![CapacitiveSensor Demo](http://www.pjrc.com/teensy/td_libs_CapacitiveSensor_1.jpg) 14 | -------------------------------------------------------------------------------- /libraries/CapacitiveSensor-0.5.1/examples/CapacitiveSensorSketch/CapacitiveSensorSketch.pde: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | * CapitiveSense Library Demo Sketch 5 | * Paul Badger 2008 6 | * Uses a high value resistor e.g. 10M between send pin and receive pin 7 | * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values. 8 | * Receive pin is the sensor pin - try different amounts of foil/metal on this pin 9 | */ 10 | 11 | 12 | CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired 13 | CapacitiveSensor cs_4_6 = CapacitiveSensor(4,6); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil 14 | CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil 15 | 16 | void setup() 17 | { 18 | cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example 19 | Serial.begin(9600); 20 | } 21 | 22 | void loop() 23 | { 24 | long start = millis(); 25 | long total1 = cs_4_2.capacitiveSensor(30); 26 | long total2 = cs_4_6.capacitiveSensor(30); 27 | long total3 = cs_4_8.capacitiveSensor(30); 28 | 29 | Serial.print(millis() - start); // check on performance in milliseconds 30 | Serial.print("\t"); // tab character for debug windown spacing 31 | 32 | Serial.print(total1); // print sensor output 1 33 | Serial.print("\t"); 34 | Serial.print(total2); // print sensor output 2 35 | Serial.print("\t"); 36 | Serial.println(total3); // print sensor output 3 37 | 38 | delay(10); // arbitrary delay to limit data to serial port 39 | } 40 | -------------------------------------------------------------------------------- /libraries/CapacitiveSensor-0.5.1/keywords.txt: -------------------------------------------------------------------------------- 1 | CapacitiveSensor KEYWORD1 2 | capacitiveSensorRaw KEYWORD2 3 | capacitiveSensor KEYWORD2 4 | set_CS_Timeout_Millis KEYWORD2 5 | reset_CS_AutoCal KEYWORD2 6 | set_CS_AutocaL_Millis KEYWORD2 7 | -------------------------------------------------------------------------------- /libraries/CapacitiveSensor-0.5.1/library.properties: -------------------------------------------------------------------------------- 1 | name=CapacitiveSensor 2 | version=0.5.1 3 | author=Paul Bagder, Paul Stoffregen 4 | maintainer=Paul Stoffregen 5 | sentence=Create capacitive sensors that can detect touch or proximity. 6 | paragraph=The capacitiveSensor library turns two or more Arduino pins into a capacitive sensor, which can sense the electrical capacitance of the human body. All the sensor setup requires is a medium to high value resistor and a piece of wire and a small (to large) piece of aluminum foil on the end. At its most sensitive, the sensor will start to sense a hand or body inches away from the sensor. 7 | category=Sensors 8 | url=http://playground.arduino.cc/Main/CapacitiveSensor 9 | architectures=stm8 10 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Clear 3 | * 4 | * Sets all of the bytes of the EEPROM to 0. 5 | * Please see eeprom_iteration for a more in depth 6 | * look at how to traverse the EEPROM. 7 | * 8 | * This example code is in the public domain. 9 | */ 10 | 11 | #include 12 | 13 | void setup() { 14 | // initialize the LED pin as an output. 15 | pinMode(13, OUTPUT); 16 | 17 | /*** 18 | Iterate through each byte of the EEPROM storage. 19 | 20 | Larger AVR processors have larger EEPROM sizes, E.g: 21 | - Arduno Duemilanove: 512b EEPROM storage. 22 | - Arduino Uno: 1kb EEPROM storage. 23 | - Arduino Mega: 4kb EEPROM storage. 24 | 25 | Rather than hard-coding the length, you should use the pre-provided length function. 26 | This will make your code portable to all AVR processors. 27 | ***/ 28 | 29 | for (int i = 0 ; i < EEPROM.length() ; i++) { 30 | EEPROM.write(i, 0); 31 | } 32 | 33 | // turn the LED on when we're done 34 | digitalWrite(13, HIGH); 35 | } 36 | 37 | void loop() { 38 | /** Empty loop. **/ 39 | } 40 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | Written by Christopher Andrews. 3 | CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). 4 | 5 | A CRC is a simple way of checking whether data has changed or become corrupted. 6 | This example calculates a CRC value directly on the EEPROM values. 7 | The purpose of this example is to highlight how the EEPROM object can be used just like an array. 8 | ***/ 9 | 10 | #include 11 | #include 12 | 13 | unsigned long eeprom_crc(void); 14 | 15 | void setup() { 16 | 17 | //Start serial 18 | Serial.begin(9600); 19 | while (!Serial) { 20 | ; // wait for serial port to connect. Needed for native USB port only 21 | } 22 | 23 | //Print length of data to run CRC on. 24 | Serial.print("EEPROM length: "); 25 | Serial.println(EEPROM.length()); 26 | 27 | //Print the result of calling eeprom_crc() 28 | Serial.print("CRC32 of EEPROM data: 0x"); 29 | Serial.println(eeprom_crc(), HEX); 30 | Serial.print("\n\nDone!"); 31 | } 32 | 33 | void loop() { 34 | /* Empty loop */ 35 | } 36 | 37 | unsigned long eeprom_crc(void) { 38 | 39 | const unsigned long crc_table[16] = { 40 | 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 41 | 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 42 | 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 43 | 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c 44 | }; 45 | 46 | unsigned long crc = ~0L; 47 | 48 | for (int index = 0 ; index < EEPROM.length() ; ++index) { 49 | crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); 50 | crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); 51 | crc = ~crc; 52 | } 53 | return crc; 54 | } 55 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_get/eeprom_get.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_get example. 3 | 4 | This shows how to use the EEPROM.get() method. 5 | 6 | To pre-set the EEPROM data, run the example sketch eeprom_put. 7 | This sketch will run without it, however, the values shown 8 | will be shown from what ever is already on the EEPROM. 9 | 10 | This may cause the serial object to print out a large string 11 | of garbage if there is no null character inside one of the strings 12 | loaded. 13 | 14 | Written by Christopher Andrews 2015 15 | Released under MIT licence. 16 | ***/ 17 | 18 | #include 19 | 20 | void secondTest(); 21 | 22 | void setup() { 23 | 24 | float f = 0.00f; //Variable to store data read from EEPROM. 25 | int eeAddress = 0; //EEPROM address to start reading from 26 | 27 | Serial.begin(9600); 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | Serial.print("Read float from EEPROM: "); 32 | 33 | //Get the float data from the EEPROM at position 'eeAddress' 34 | EEPROM.get(eeAddress, f); 35 | Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. 36 | 37 | /*** 38 | As get also returns a reference to 'f', you can use it inline. 39 | E.g: Serial.print( EEPROM.get( eeAddress, f ) ); 40 | ***/ 41 | 42 | /*** 43 | Get can be used with custom structures too. 44 | I have separated this into an extra function. 45 | ***/ 46 | 47 | secondTest(); //Run the next test. 48 | } 49 | 50 | struct MyObject { 51 | float field1; 52 | byte field2; 53 | char name[10]; 54 | }; 55 | 56 | void secondTest() { 57 | int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. 58 | 59 | MyObject customVar; //Variable to store custom object read from EEPROM. 60 | EEPROM.get(eeAddress, customVar); 61 | 62 | Serial.println("Read custom object from EEPROM: "); 63 | Serial.println(customVar.field1); 64 | Serial.println(customVar.field2); 65 | Serial.println(customVar.name); 66 | } 67 | 68 | void loop() { 69 | /* Empty loop */ 70 | } 71 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_iteration example. 3 | 4 | A set of example snippets highlighting the 5 | simplest methods for traversing the EEPROM. 6 | 7 | Running this sketch is not necessary, this is 8 | simply highlighting certain programming methods. 9 | 10 | Written by Christopher Andrews 2015 11 | Released under MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | void setup() { 17 | 18 | /*** 19 | Iterate the EEPROM using a for loop. 20 | ***/ 21 | 22 | for (int index = 0 ; index < EEPROM.length() ; index++) { 23 | 24 | //Add one to each cell in the EEPROM 25 | EEPROM[ index ] += 1; 26 | } 27 | 28 | /*** 29 | Iterate the EEPROM using a while loop. 30 | ***/ 31 | 32 | int index = 0; 33 | 34 | while (index < EEPROM.length()) { 35 | 36 | //Add one to each cell in the EEPROM 37 | EEPROM[ index ] += 1; 38 | index++; 39 | } 40 | 41 | /*** 42 | Iterate the EEPROM using a do-while loop. 43 | ***/ 44 | 45 | int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. 46 | 47 | do { 48 | 49 | //Add one to each cell in the EEPROM 50 | EEPROM[ idx ] += 1; 51 | idx++; 52 | } while (idx < EEPROM.length()); 53 | 54 | 55 | } //End of setup function. 56 | 57 | void loop() {} 58 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_put/eeprom_put.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | eeprom_put example. 3 | 4 | This shows how to use the EEPROM.put() method. 5 | Also, this sketch will pre-set the EEPROM data for the 6 | example sketch eeprom_get. 7 | 8 | Note, unlike the single byte version EEPROM.write(), 9 | the put method will use update semantics. As in a byte 10 | will only be written to the EEPROM if the data is actually 11 | different. 12 | 13 | Written by Christopher Andrews 2015 14 | Released under MIT licence. 15 | ***/ 16 | 17 | #include 18 | 19 | struct MyObject { 20 | float field1; 21 | byte field2; 22 | char name[10]; 23 | }; 24 | 25 | void setup() { 26 | 27 | Serial.begin(9600); 28 | while (!Serial) { 29 | ; // wait for serial port to connect. Needed for native USB port only 30 | } 31 | 32 | float f = 123.456f; //Variable to store in EEPROM. 33 | int eeAddress = 0; //Location we want the data to be put. 34 | 35 | 36 | //One simple call, with the address first and the object second. 37 | EEPROM.put(eeAddress, f); 38 | 39 | Serial.println("Written float data type!"); 40 | 41 | /** Put is designed for use with custom structures also. **/ 42 | 43 | //Data to store. 44 | MyObject customVar = { 45 | 3.14f, 46 | 65, 47 | "Working!" 48 | }; 49 | 50 | eeAddress += sizeof(float); //Move address to the next byte after float 'f'. 51 | 52 | EEPROM.put(eeAddress, customVar); 53 | Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); 54 | } 55 | 56 | void loop() { 57 | /* Empty loop */ 58 | } 59 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_read/eeprom_read.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Read 3 | * 4 | * Reads the value of each byte of the EEPROM and prints it 5 | * to the computer. 6 | * This example code is in the public domain. 7 | */ 8 | 9 | #include 10 | 11 | // start reading from the first byte (address 0) of the EEPROM 12 | int address = 0; 13 | byte value; 14 | 15 | void setup() { 16 | // initialize serial and wait for port to open: 17 | Serial.begin(9600); 18 | while (!Serial) { 19 | ; // wait for serial port to connect. Needed for native USB port only 20 | } 21 | } 22 | 23 | void loop() { 24 | // read a byte from the current address of the EEPROM 25 | value = EEPROM.read(address); 26 | 27 | Serial.print(address); 28 | Serial.print("\t"); 29 | Serial.print(value, DEC); 30 | Serial.println(); 31 | 32 | /*** 33 | Advance to the next address, when at the end restart at the beginning. 34 | 35 | Larger AVR processors have larger EEPROM sizes, E.g: 36 | - Arduno Duemilanove: 512b EEPROM storage. 37 | - Arduino Uno: 1kb EEPROM storage. 38 | - Arduino Mega: 4kb EEPROM storage. 39 | 40 | Rather than hard-coding the length, you should use the pre-provided length function. 41 | This will make your code portable to all AVR processors. 42 | ***/ 43 | address = address + 1; 44 | if (address == EEPROM.length()) { 45 | address = 0; 46 | } 47 | 48 | /*** 49 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 50 | EEPROM address is also doable by a bitwise and of the length - 1. 51 | 52 | ++address &= EEPROM.length() - 1; 53 | ***/ 54 | 55 | delay(500); 56 | } 57 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_update/eeprom_update.ino: -------------------------------------------------------------------------------- 1 | /*** 2 | EEPROM Update method 3 | 4 | Stores values read from analog input 0 into the EEPROM. 5 | These values will stay in the EEPROM when the board is 6 | turned off and may be retrieved later by another sketch. 7 | 8 | If a value has not changed in the EEPROM, it is not overwritten 9 | which would reduce the life span of the EEPROM unnecessarily. 10 | 11 | Released using MIT licence. 12 | ***/ 13 | 14 | #include 15 | 16 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 17 | int address = 0; 18 | 19 | void setup() { 20 | /** EMpty setup **/ 21 | } 22 | 23 | void loop() { 24 | /*** 25 | need to divide by 4 because analog inputs range from 26 | 0 to 1023 and each byte of the EEPROM can only hold a 27 | value from 0 to 255. 28 | ***/ 29 | int val = analogRead(0) / 4; 30 | 31 | /*** 32 | Update the particular EEPROM cell. 33 | these values will remain there when the board is 34 | turned off. 35 | ***/ 36 | EEPROM.update(address, val); 37 | 38 | /*** 39 | The function EEPROM.update(address, val) is equivalent to the following: 40 | 41 | if( EEPROM.read(address) != val ){ 42 | EEPROM.write(address, val); 43 | } 44 | ***/ 45 | 46 | 47 | /*** 48 | Advance to the next address, when at the end restart at the beginning. 49 | 50 | Larger AVR processors have larger EEPROM sizes, E.g: 51 | - Arduno Duemilanove: 512b EEPROM storage. 52 | - Arduino Uno: 1kb EEPROM storage. 53 | - Arduino Mega: 4kb EEPROM storage. 54 | 55 | Rather than hard-coding the length, you should use the pre-provided length function. 56 | This will make your code portable to all AVR processors. 57 | ***/ 58 | address = address + 1; 59 | if (address == EEPROM.length()) { 60 | address = 0; 61 | } 62 | 63 | /*** 64 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 65 | EEPROM address is also doable by a bitwise and of the length - 1. 66 | 67 | ++address &= EEPROM.length() - 1; 68 | ***/ 69 | 70 | delay(100); 71 | } 72 | -------------------------------------------------------------------------------- /libraries/EEPROM/examples/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Write 3 | * 4 | * Stores values read from analog input 0 into the EEPROM. 5 | * These values will stay in the EEPROM when the board is 6 | * turned off and may be retrieved later by another sketch. 7 | */ 8 | 9 | #include 10 | 11 | /** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ 12 | int addr = 0; 13 | 14 | void setup() { 15 | /** Empty setup. **/ 16 | } 17 | 18 | void loop() { 19 | /*** 20 | Need to divide by 4 because analog inputs range from 21 | 0 to 1023 and each byte of the EEPROM can only hold a 22 | value from 0 to 255. 23 | ***/ 24 | 25 | int val = analogRead(0) / 4; 26 | 27 | /*** 28 | Write the value to the appropriate byte of the EEPROM. 29 | these values will remain there when the board is 30 | turned off. 31 | ***/ 32 | 33 | EEPROM.write(addr, val); 34 | 35 | /*** 36 | Advance to the next address, when at the end restart at the beginning. 37 | 38 | Larger AVR processors have larger EEPROM sizes, E.g: 39 | - Arduno Duemilanove: 512b EEPROM storage. 40 | - Arduino Uno: 1kb EEPROM storage. 41 | - Arduino Mega: 4kb EEPROM storage. 42 | 43 | Rather than hard-coding the length, you should use the pre-provided length function. 44 | This will make your code portable to all AVR processors. 45 | ***/ 46 | addr = addr + 1; 47 | if (addr == EEPROM.length()) { 48 | addr = 0; 49 | } 50 | 51 | /*** 52 | As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an 53 | EEPROM address is also doable by a bitwise and of the length - 1. 54 | 55 | ++addr &= EEPROM.length() - 1; 56 | ***/ 57 | 58 | 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /libraries/EEPROM/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For EEPROM 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EEPROM KEYWORD1 10 | EERef KEYWORD1 11 | EEPtr KEYWORD2 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | update KEYWORD2 18 | 19 | ####################################### 20 | # Constants (LITERAL1) 21 | ####################################### 22 | 23 | -------------------------------------------------------------------------------- /libraries/EEPROM/library.properties: -------------------------------------------------------------------------------- 1 | name=EEPROM 2 | version=2.0 3 | author=Arduino, Christopher Andrews 4 | maintainer=Arduino 5 | sentence=Enables reading and writing to the permanent board storage. For all Arduino boards BUT Arduino DUE and Arduino ZERO. 6 | paragraph= 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/EEPROM 9 | architectures=stm8 10 | -------------------------------------------------------------------------------- /libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital Pot Control 3 | 4 | This example controls an Analog Devices AD5206 digital potentiometer. 5 | The AD5206 has 6 potentiometer channels. Each channel's pins are labeled 6 | A - connect this to voltage 7 | W - this is the pot's wiper, which changes when you set it 8 | B - connect this to ground. 9 | 10 | The AD5206 is SPI-compatible,and to command it, you send two bytes, 11 | one with the channel number (0 - 5) and one with the resistance value for the 12 | channel (0 - 255). 13 | 14 | The circuit: 15 | * All A pins of AD5206 connected to +5V 16 | * All B pins of AD5206 connected to ground 17 | * An LED and a 220-ohm resisor in series connected from each W pin to ground 18 | * CS - to digital pin 10 (SS pin) 19 | * SDI - to digital pin 11 (MOSI pin) 20 | * CLK - to digital pin 13 (SCK pin) 21 | 22 | created 10 Aug 2010 23 | by Tom Igoe 24 | 25 | Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 26 | 27 | */ 28 | 29 | 30 | // inslude the SPI library: 31 | #include 32 | 33 | 34 | // set pin 10 as the slave select for the digital pot: 35 | const int slaveSelectPin = 10; 36 | 37 | void digitalPotWrite(int address, int value); 38 | 39 | void setup() { 40 | // set the slaveSelectPin as an output: 41 | pinMode(slaveSelectPin, OUTPUT); 42 | // initialize SPI: 43 | SPI.begin(); 44 | } 45 | 46 | void loop() { 47 | // go through the six channels of the digital pot: 48 | for (int channel = 0; channel < 6; channel++) { 49 | // change the resistance on this channel from min to max: 50 | for (int level = 0; level < 255; level++) { 51 | digitalPotWrite(channel, level); 52 | delay(10); 53 | } 54 | // wait a second at the top: 55 | delay(100); 56 | // change the resistance on this channel from max to min: 57 | for (int level = 0; level < 255; level++) { 58 | digitalPotWrite(channel, 255 - level); 59 | delay(10); 60 | } 61 | } 62 | 63 | } 64 | 65 | void digitalPotWrite(int address, int value) { 66 | // take the SS pin low to select the chip: 67 | digitalWrite(slaveSelectPin, LOW); 68 | // send in the address and value via SPI: 69 | SPI.transfer(address); 70 | SPI.transfer(value); 71 | // take the SS pin high to de-select the chip: 72 | digitalWrite(slaveSelectPin, HIGH); 73 | } 74 | -------------------------------------------------------------------------------- /libraries/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | #setBitOrder KEYWORD2 18 | setDataMode KEYWORD2 19 | setClockDivider KEYWORD2 20 | setMISO KEYWORD2 21 | setMOSI KEYWORD2 22 | setSCLK KEYWORD2 23 | setSSEL KEYWORD2 24 | 25 | ####################################### 26 | # Constants (LITERAL1) 27 | ####################################### 28 | SPI_MODE0 LITERAL1 29 | SPI_MODE1 LITERAL1 30 | SPI_MODE2 LITERAL1 31 | SPI_MODE3 LITERAL1 32 | 33 | SPI_CONTINUE LITERAL1 34 | SPI_LAST LITERAL1 35 | -------------------------------------------------------------------------------- /libraries/SPI/library.properties: -------------------------------------------------------------------------------- 1 | name=SPI 2 | version=1.0 3 | author=Arduino, Wi6Labs 4 | maintainer=stm32duino 5 | sentence=Enables the communication with devices that use the Serial Peripheral Interface (SPI) Bus. 6 | paragraph=This library is based on the official Arduino SPI library and adapted to STM8 boards. 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/SPI 9 | architectures=stm8 10 | -------------------------------------------------------------------------------- /libraries/Servo/README.adoc: -------------------------------------------------------------------------------- 1 | = Servo Library for Arduino = 2 | 3 | This library allows an Arduino board to control RC (hobby) servo motors. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/Servo 7 | 8 | == License == 9 | 10 | Copyright (c) 2013 Arduino LLC. All right reserved. 11 | Copyright (c) 2009 Michael Margolis. All right reserved. 12 | 13 | This library is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation; either 16 | version 2.1 of the License, or (at your option) any later version. 17 | 18 | This library is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | Lesser General Public License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with this library; if not, write to the Free Software 25 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | -------------------------------------------------------------------------------- /libraries/Servo/examples/Knob/Knob.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Controlling a servo position using a potentiometer (variable resistor) 3 | by Michal Rinott 4 | 5 | modified on 8 Nov 2013 6 | by Scott Fitzgerald 7 | http://www.arduino.cc/en/Tutorial/Knob 8 | */ 9 | 10 | #include 11 | 12 | Servo myservo; // create servo object to control a servo 13 | 14 | int potpin = 0; // analog pin used to connect the potentiometer 15 | int val; // variable to read the value from the analog pin 16 | 17 | void setup() { 18 | myservo.attach(9); // attaches the servo on pin 9 to the servo object 19 | } 20 | 21 | void loop() { 22 | val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) 23 | val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) 24 | myservo.write(val); // sets the servo position according to the scaled value 25 | delay(15); // waits for the servo to get there 26 | } 27 | 28 | -------------------------------------------------------------------------------- /libraries/Servo/examples/Sweep/Sweep.ino: -------------------------------------------------------------------------------- 1 | /* Sweep 2 | by BARRAGAN 3 | This example code is in the public domain. 4 | 5 | modified 8 Nov 2013 6 | by Scott Fitzgerald 7 | http://www.arduino.cc/en/Tutorial/Sweep 8 | */ 9 | 10 | #include 11 | 12 | Servo myservo; // create servo object to control a servo 13 | // twelve servo objects can be created on most boards 14 | 15 | int pos = 0; // variable to store the servo position 16 | 17 | void setup() { 18 | myservo.attach(9); // attaches the servo on pin 9 to the servo object 19 | } 20 | 21 | void loop() { 22 | for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees 23 | // in steps of 1 degree 24 | myservo.write(pos); // tell servo to go to position in variable 'pos' 25 | delay(15); // waits 15ms for the servo to reach the position 26 | } 27 | for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 28 | myservo.write(pos); // tell servo to go to position in variable 'pos' 29 | delay(15); // waits 15ms for the servo to reach the position 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /libraries/Servo/examples/fs90r/fs90r.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Use servo library to control a FS90R motor 3 | 4 | Motor information : 5 | http://www.feetechrc.com/product/analog-servo/micro-1-3kg-cm-360-degree-continuous-rotation-servo-fs90r/ 6 | Must respect the pulse range in order not to damage servo. 7 | 8 | */ 9 | 10 | #include 11 | 12 | Servo fs90r; // create servo object to control a servo 13 | 14 | int potpin = 0; // analog pin used to connect the potentiometer 15 | int val; // variable to read the value from the analog pin 16 | int servopin = 9; // pin used to connect the servo 17 | 18 | void setup() { 19 | Serial.begin(115200); 20 | 21 | fs90r.attach(servopin, 900, 2100); // attaches the servo on pin 9 to the servo object 22 | // Be carefull to min and max values... 23 | } 24 | 25 | void loop() { 26 | val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) 27 | val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180, at 90, 28 | // motor is stopped) 29 | 30 | Serial.print("val = "); 31 | Serial.println(val); 32 | 33 | fs90r.write(val); // sets the servo speed according to the scaled value 34 | delay(15); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /libraries/Servo/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map Servo 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Servo KEYWORD1 Servo 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | attach KEYWORD2 15 | detach KEYWORD2 16 | write KEYWORD2 17 | read KEYWORD2 18 | attached KEYWORD2 19 | writeMicroseconds KEYWORD2 20 | readMicroseconds KEYWORD2 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | -------------------------------------------------------------------------------- /libraries/Servo/library.properties: -------------------------------------------------------------------------------- 1 | name=Servo 2 | version=1.1.2 3 | author=Michael Margolis, Arduino 4 | maintainer=Arduino 5 | sentence=Allows Arduino/Genuino boards to control a variety of servo motors. 6 | paragraph=This library can control a great number of servos.
It makes careful use of timers: the library can control 12 servos using only 1 timer.
On the Arduino Due you can control up to 60 servos.
7 | category=Device Control 8 | url=http://www.arduino.cc/en/Reference/Servo 9 | architectures=avr,sam,samd,nrf52,stm32f4,stm8 10 | -------------------------------------------------------------------------------- /libraries/Servo/src/avr/ServoTimers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 3 | Copyright (c) 2009 Michael Margolis. 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 | /* 21 | * Defines for 16 bit timers used with Servo library 22 | * 23 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 24 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 25 | * _Nbr_16timers indicates how many 16 bit timers are available. 26 | */ 27 | 28 | /** 29 | * AVR Only definitions 30 | * -------------------- 31 | */ 32 | 33 | // Say which 16 bit timers can be used and in what order 34 | #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 35 | #define _useTimer5 36 | #define _useTimer1 37 | #define _useTimer3 38 | #define _useTimer4 39 | typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t; 40 | 41 | #elif defined(__AVR_ATmega32U4__) 42 | #define _useTimer1 43 | typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t; 44 | 45 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) 46 | #define _useTimer3 47 | #define _useTimer1 48 | typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t; 49 | 50 | #elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) 51 | #define _useTimer3 52 | #define _useTimer1 53 | typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t; 54 | 55 | #else // everything else 56 | #define _useTimer1 57 | typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t; 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /libraries/Servo/src/sam/ServoTimers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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 GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* 20 | * Defines for 16 bit timers used with Servo library 21 | * 22 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 23 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 24 | * _Nbr_16timers indicates how many 16 bit timers are available. 25 | */ 26 | 27 | /** 28 | * SAM Only definitions 29 | * -------------------- 30 | */ 31 | 32 | // For SAM3X: 33 | #define _useTimer1 34 | #define _useTimer2 35 | #define _useTimer3 36 | #define _useTimer4 37 | #define _useTimer5 38 | 39 | /* 40 | TC0, chan 0 => TC0_Handler 41 | TC0, chan 1 => TC1_Handler 42 | TC0, chan 2 => TC2_Handler 43 | TC1, chan 0 => TC3_Handler 44 | TC1, chan 1 => TC4_Handler 45 | TC1, chan 2 => TC5_Handler 46 | TC2, chan 0 => TC6_Handler 47 | TC2, chan 1 => TC7_Handler 48 | TC2, chan 2 => TC8_Handler 49 | */ 50 | 51 | #if defined (_useTimer1) 52 | #define TC_FOR_TIMER1 TC1 53 | #define CHANNEL_FOR_TIMER1 0 54 | #define ID_TC_FOR_TIMER1 ID_TC3 55 | #define IRQn_FOR_TIMER1 TC3_IRQn 56 | #define HANDLER_FOR_TIMER1 TC3_Handler 57 | #endif 58 | #if defined (_useTimer2) 59 | #define TC_FOR_TIMER2 TC1 60 | #define CHANNEL_FOR_TIMER2 1 61 | #define ID_TC_FOR_TIMER2 ID_TC4 62 | #define IRQn_FOR_TIMER2 TC4_IRQn 63 | #define HANDLER_FOR_TIMER2 TC4_Handler 64 | #endif 65 | #if defined (_useTimer3) 66 | #define TC_FOR_TIMER3 TC1 67 | #define CHANNEL_FOR_TIMER3 2 68 | #define ID_TC_FOR_TIMER3 ID_TC5 69 | #define IRQn_FOR_TIMER3 TC5_IRQn 70 | #define HANDLER_FOR_TIMER3 TC5_Handler 71 | #endif 72 | #if defined (_useTimer4) 73 | #define TC_FOR_TIMER4 TC0 74 | #define CHANNEL_FOR_TIMER4 2 75 | #define ID_TC_FOR_TIMER4 ID_TC2 76 | #define IRQn_FOR_TIMER4 TC2_IRQn 77 | #define HANDLER_FOR_TIMER4 TC2_Handler 78 | #endif 79 | #if defined (_useTimer5) 80 | #define TC_FOR_TIMER5 TC0 81 | #define CHANNEL_FOR_TIMER5 0 82 | #define ID_TC_FOR_TIMER5 ID_TC0 83 | #define IRQn_FOR_TIMER5 TC0_IRQn 84 | #define HANDLER_FOR_TIMER5 TC0_Handler 85 | #endif 86 | 87 | typedef enum { _timer1, _timer2, _timer3, _timer4, _timer5, _Nbr_16timers } timer16_Sequence_t ; 88 | 89 | -------------------------------------------------------------------------------- /libraries/Servo/src/samd/ServoTimers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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 GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* 20 | * Defines for 16 bit timers used with Servo library 21 | * 22 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 23 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 24 | * _Nbr_16timers indicates how many 16 bit timers are available. 25 | */ 26 | 27 | #ifndef __SERVO_TIMERS_H__ 28 | #define __SERVO_TIMERS_H__ 29 | 30 | /** 31 | * SAMD Only definitions 32 | * --------------------- 33 | */ 34 | 35 | // For SAMD: 36 | #define _useTimer1 37 | //#define _useTimer2 // <- TODO do not activate until the code in Servo.cpp has been changed in order 38 | // to manage more than one channel per timer on the SAMD architecture 39 | 40 | #if defined (_useTimer1) 41 | #define TC_FOR_TIMER1 TC4 42 | #define CHANNEL_FOR_TIMER1 0 43 | #define INTENSET_BIT_FOR_TIMER_1 TC_INTENSET_MC0 44 | #define INTENCLR_BIT_FOR_TIMER_1 TC_INTENCLR_MC0 45 | #define INTFLAG_BIT_FOR_TIMER_1 TC_INTFLAG_MC0 46 | #define ID_TC_FOR_TIMER1 ID_TC4 47 | #define IRQn_FOR_TIMER1 TC4_IRQn 48 | #define HANDLER_FOR_TIMER1 TC4_Handler 49 | #define GCM_FOR_TIMER_1 GCM_TC4_TC5 50 | #endif 51 | #if defined (_useTimer2) 52 | #define TC_FOR_TIMER2 TC4 53 | #define CHANNEL_FOR_TIMER2 1 54 | #define INTENSET_BIT_FOR_TIMER_2 TC_INTENSET_MC1 55 | #define INTENCLR_BIT_FOR_TIMER_2 TC_INTENCLR_MC1 56 | #define ID_TC_FOR_TIMER2 ID_TC4 57 | #define IRQn_FOR_TIMER2 TC4_IRQn 58 | #define HANDLER_FOR_TIMER2 TC4_Handler 59 | #define GCM_FOR_TIMER_2 GCM_TC4_TC5 60 | #endif 61 | 62 | typedef enum { 63 | #if defined (_useTimer1) 64 | _timer1, 65 | #endif 66 | #if defined (_useTimer2) 67 | _timer2, 68 | #endif 69 | _Nbr_16timers } timer16_Sequence_t; 70 | 71 | #endif // __SERVO_TIMERS_H__ 72 | -------------------------------------------------------------------------------- /libraries/Servo/src/stm8/ServoTimers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library 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 GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | /* 20 | * Defines for 16 bit timers used with Servo library 21 | * 22 | * If _useTimerX is defined then TimerX is a 16 bit timer on the current board 23 | * timer16_Sequence_t enumerates the sequence that the timers should be allocated 24 | * _Nbr_16timers indicates how many 16 bit timers are available. 25 | */ 26 | 27 | #ifndef __SERVO_TIMERS_H__ 28 | #define __SERVO_TIMERS_H__ 29 | 30 | // Uses one timer. Allows until 12 servos. 31 | typedef enum 32 | { 33 | _timer1, 34 | _Nbr_16timers 35 | } timer16_Sequence_t; 36 | 37 | #endif // __SERVO_TIMERS_H__ 38 | -------------------------------------------------------------------------------- /libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde: -------------------------------------------------------------------------------- 1 | // I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder 2 | // by Nicholas Zambetti 3 | // and James Tichenor 4 | 5 | // Demonstrates use of the Wire library reading data from the 6 | // Devantech Utrasonic Rangers SFR08 and SFR10 7 | 8 | // Created 29 April 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | Serial.begin(9600); // start serial communication at 9600bps 19 | } 20 | 21 | int reading = 0; 22 | 23 | void loop() 24 | { 25 | // step 1: instruct sensor to read echoes 26 | Wire.beginTransmission(112); // transmit to device #112 (0x70) 27 | // the address specified in the datasheet is 224 (0xE0) 28 | // but i2c adressing uses the high 7 bits so it's 112 29 | Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) 30 | Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) 31 | // use 0x51 for centimeters 32 | // use 0x52 for ping microseconds 33 | Wire.endTransmission(); // stop transmitting 34 | 35 | // step 2: wait for readings to happen 36 | delay(70); // datasheet suggests at least 65 milliseconds 37 | 38 | // step 3: instruct sensor to return a particular echo reading 39 | Wire.beginTransmission(112); // transmit to device #112 40 | Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) 41 | Wire.endTransmission(); // stop transmitting 42 | 43 | // step 4: request reading from sensor 44 | Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 45 | 46 | // step 5: receive reading from sensor 47 | if(2 <= Wire.available()) // if two bytes were received 48 | { 49 | reading = Wire.read(); // receive high byte (overwrites previous reading) 50 | reading = reading << 8; // shift high byte to be high 8 bits 51 | reading |= Wire.read(); // receive low byte as lower 8 bits 52 | Serial.println(reading); // print the reading 53 | } 54 | 55 | delay(250); // wait a bit since people have to read the output :) 56 | } 57 | 58 | 59 | /* 60 | 61 | // The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) 62 | // usage: changeAddress(0x70, 0xE6); 63 | 64 | void changeAddress(byte oldAddress, byte newAddress) 65 | { 66 | Wire.beginTransmission(oldAddress); 67 | Wire.write(byte(0x00)); 68 | Wire.write(byte(0xA0)); 69 | Wire.endTransmission(); 70 | 71 | Wire.beginTransmission(oldAddress); 72 | Wire.write(byte(0x00)); 73 | Wire.write(byte(0xAA)); 74 | Wire.endTransmission(); 75 | 76 | Wire.beginTransmission(oldAddress); 77 | Wire.write(byte(0x00)); 78 | Wire.write(byte(0xA5)); 79 | Wire.endTransmission(); 80 | 81 | Wire.beginTransmission(oldAddress); 82 | Wire.write(byte(0x00)); 83 | Wire.write(newAddress); 84 | Wire.endTransmission(); 85 | } 86 | 87 | */ 88 | -------------------------------------------------------------------------------- /libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | #include 16 | 17 | void setup() 18 | { 19 | Wire.begin(); // join i2c bus (address optional for master) 20 | } 21 | 22 | byte val = 0; 23 | 24 | void loop() 25 | { 26 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 27 | // device address is specified in datasheet 28 | Wire.write(byte(0x00)); // sends instruction byte 29 | Wire.write(val); // sends potentiometer value byte 30 | Wire.endTransmission(); // stop transmitting 31 | 32 | val++; // increment value 33 | if(val == 64) // if reached 64th position (max) 34 | { 35 | val = 0; // start over from lowest value 36 | } 37 | delay(500); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_reader/master_reader.pde: -------------------------------------------------------------------------------- 1 | // Wire Master Reader 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Reads data from an I2C/TWI slave device 6 | // Refer to the "Wire Slave Sender" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | Serial.begin(9600); // start serial for output 19 | } 20 | 21 | void loop() 22 | { 23 | Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 24 | 25 | while(Wire.available()) // slave may send less than requested 26 | { 27 | char c = Wire.read(); // receive a byte as character 28 | Serial.print(c); // print the character 29 | } 30 | 31 | delay(500); 32 | } 33 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_reader_writer/master_reader_writer.ino: -------------------------------------------------------------------------------- 1 | /* Wire Master Reader Writer 2 | by Wi6Labs 3 | 4 | Demonstrates use of the Wire library. 5 | Reads/writes data from/to an I2C/TWI slave device. 6 | Refer to the "Wire Slave Sender Receiver" example for use with this. 7 | 8 | Created 27 June 2017 9 | Updated 14 August 2017 10 | - this example is now common to all STM32 boards 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | #include 16 | 17 | #define I2C_ADDR 2 18 | 19 | byte x = 0; 20 | 21 | void setup() 22 | { 23 | Wire.begin(); // join i2c bus (address optional for master) 24 | Serial.begin(9600); // start serial for output 25 | } 26 | 27 | void loop() 28 | { 29 | Wire.requestFrom(I2C_ADDR, 6); // request 6 bytes from slave device 30 | 31 | while(Wire.available()) // slave may send less than requested 32 | { 33 | char c = Wire.read(); // receive a byte as character 34 | Serial.print(c); // print the character 35 | } 36 | 37 | delay(10); 38 | 39 | Wire.beginTransmission(I2C_ADDR); // transmit to device 40 | Wire.write("x is "); // sends five bytes 41 | Wire.write(x); // sends one byte 42 | Wire.endTransmission(); // stop transmitting 43 | x++; 44 | 45 | delay(500); 46 | } 47 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_writer/master_writer.pde: -------------------------------------------------------------------------------- 1 | // Wire Master Writer 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Writes data to an I2C/TWI slave device 6 | // Refer to the "Wire Slave Receiver" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | } 19 | 20 | byte x = 0; 21 | 22 | void loop() 23 | { 24 | Wire.beginTransmission(4); // transmit to device #4 25 | Wire.write("x is "); // sends five bytes 26 | Wire.write(x); // sends one byte 27 | Wire.endTransmission(); // stop transmitting 28 | 29 | x++; 30 | delay(500); 31 | } 32 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_receiver/slave_receiver.pde: -------------------------------------------------------------------------------- 1 | // Wire Slave Receiver 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Receives data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Writer" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(4); // join i2c bus with address #4 18 | Wire.onReceive(receiveEvent); // register event 19 | Serial.begin(9600); // start serial for output 20 | } 21 | 22 | void loop() 23 | { 24 | delay(100); 25 | } 26 | 27 | // function that executes whenever data is received from master 28 | // this function is registered as an event, see setup() 29 | void receiveEvent(int howMany) 30 | { 31 | while(1 < Wire.available()) // loop through all but the last 32 | { 33 | char c = Wire.read(); // receive byte as a character 34 | Serial.print(c); // print the character 35 | } 36 | int x = Wire.read(); // receive byte as an integer 37 | Serial.println(x); // print the integer 38 | } 39 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_sender/slave_sender.pde: -------------------------------------------------------------------------------- 1 | // Wire Slave Sender 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Sends data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Reader" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(2); // join i2c bus with address #2 18 | Wire.onRequest(requestEvent); // register event 19 | } 20 | 21 | void loop() 22 | { 23 | delay(100); 24 | } 25 | 26 | // function that executes whenever data is requested by master 27 | // this function is registered as an event, see setup() 28 | void requestEvent() 29 | { 30 | Wire.write("hello "); // respond with message of 6 bytes 31 | // as expected by master 32 | } 33 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_sender_receiver/slave_sender_receiver.ino: -------------------------------------------------------------------------------- 1 | /* Wire Slave Receiver 2 | by Wi6Labs 3 | 4 | Demonstrates use of the Wire library. 5 | Receives/sends data as an I2C/TWI slave device. 6 | Refer to the "Wire Master Reader Writer" example for use with this. 7 | 8 | Created 27 June 2017 9 | Updated 14 August 2017 10 | - this example is now common to all STM32 boards 11 | 12 | This example code is in the public domain. 13 | */ 14 | 15 | #include 16 | 17 | #define I2C_ADDR 2 18 | 19 | void setup() 20 | { 21 | Wire.begin(I2C_ADDR); // join i2c bus with address #4 22 | Wire.onRequest(requestEvent); // register event 23 | Wire.onReceive(receiveEvent); // register event 24 | Serial.begin(9600); // start serial for output 25 | } 26 | 27 | void loop() 28 | { 29 | //empty loop 30 | } 31 | 32 | // function that executes whenever data is received from master 33 | // this function is registered as an event, see setup() 34 | void receiveEvent(int howMany) 35 | { 36 | while(1 < Wire.available()) // loop through all but the last 37 | { 38 | char c = Wire.read(); // receive byte as a character 39 | Serial.print(c); // print the character 40 | } 41 | int x = Wire.read(); // receive byte as an integer 42 | Serial.println(x); // print the integer 43 | } 44 | 45 | // function that executes whenever data is requested by master 46 | // this function is registered as an event, see setup() 47 | void requestEvent() 48 | { 49 | Wire.write("hello\n"); // respond with message of 6 bytes 50 | // as expected by master 51 | } 52 | -------------------------------------------------------------------------------- /libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | setClock KEYWORD2 15 | beginTransmission KEYWORD2 16 | endTransmission KEYWORD2 17 | requestFrom KEYWORD2 18 | onReceive KEYWORD2 19 | onRequest KEYWORD2 20 | setSCL KEYWORD2 21 | setSDA KEYWORD2 22 | 23 | ####################################### 24 | # Instances (KEYWORD2) 25 | ####################################### 26 | 27 | Wire KEYWORD2 28 | Wire1 KEYWORD2 29 | 30 | ####################################### 31 | # Constants (LITERAL1) 32 | ####################################### 33 | -------------------------------------------------------------------------------- /libraries/Wire/library.properties: -------------------------------------------------------------------------------- 1 | name=Wire 2 | version=1.0 3 | author=Arduino, Wi6Labs 4 | maintainer=stm32duino 5 | sentence=Allows the communication between devices or sensors connected via Two Wire (I2C) Interface Bus. 6 | paragraph= 7 | category=Communication 8 | url=http://www.arduino.cc/en/Reference/Wire 9 | architectures=stm8 10 | -------------------------------------------------------------------------------- /libraries/Wire/src/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.h - TWI/I2C library for Arduino & Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. 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 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | */ 21 | 22 | #ifndef TwoWire_h 23 | #define TwoWire_h 24 | 25 | #include 26 | #include "Stream.h" 27 | #include "Arduino.h" 28 | 29 | #define BUFFER_LENGTH 32 30 | 31 | #define MASTER_ADDRESS 0x33 32 | 33 | class TwoWire : public Stream 34 | { 35 | private: 36 | uint8_t rxBuffer[BUFFER_LENGTH]; 37 | uint8_t rxBufferIndex; 38 | uint8_t rxBufferLength; 39 | 40 | uint8_t txAddress; 41 | uint8_t txBuffer[BUFFER_LENGTH]; 42 | uint8_t txBufferIndex; 43 | uint8_t txBufferLength; 44 | 45 | uint8_t transmitting; 46 | 47 | uint8_t ownAddress; 48 | bool master; 49 | i2c_t _i2c; 50 | 51 | static void (*user_onRequest)(void); 52 | static void (*user_onReceive)(int); 53 | static void onRequestService(void); 54 | static void onReceiveService(uint8_t *, int); 55 | 56 | public: 57 | TwoWire(); 58 | TwoWire(uint8_t sda, uint8_t scl); 59 | void begin(); 60 | void begin(uint8_t); 61 | void begin(int); 62 | void end(); 63 | void setClock(uint32_t); 64 | void beginTransmission(uint8_t); 65 | void beginTransmission(int); 66 | uint8_t endTransmission(void); 67 | uint8_t endTransmission(uint8_t); 68 | uint8_t requestFrom(uint8_t, uint8_t); 69 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); 70 | uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t); 71 | uint8_t requestFrom(int, int); 72 | uint8_t requestFrom(int, int, int); 73 | virtual size_t write(uint8_t); 74 | virtual size_t write(const uint8_t *, size_t); 75 | virtual int available(void); 76 | virtual int read(void); 77 | virtual int peek(void); 78 | virtual void flush(void); 79 | void onReceive(void (*)(int)); 80 | void onRequest(void (*)(void)); 81 | 82 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 83 | inline size_t write(long n) { return write((uint8_t)n); } 84 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 85 | inline size_t write(int n) { return write((uint8_t)n); } 86 | using Print::write; 87 | }; 88 | 89 | extern TwoWire Wire; 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /programmers.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/programmers.txt -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/inc/stm8l15x_irtim.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8l15x_irtim.h 4 | * @author MCD Application Team 5 | * @version V1.6.1 6 | * @date 30-September-2014 7 | * @brief This file contains all the functions prototypes for the IRTIM firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8L15x_IRTIM_H 31 | #define __STM8L15x_IRTIM_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8l15x.h" 35 | 36 | /** @addtogroup STM8L15x_StdPeriph_Driver 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup IRTIM 41 | * @{ 42 | */ 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macros -----------------------------------------------------------*/ 47 | /* Exported functions --------------------------------------------------------*/ 48 | 49 | /* IRTIM configuration ********************************************************/ 50 | void IRTIM_DeInit(void); 51 | void IRTIM_Cmd(FunctionalState NewState); 52 | void IRTIM_HighSinkODCmd(FunctionalState NewState); 53 | 54 | /* IRITM status management ****************************************************/ 55 | FunctionalState IRTIM_GetStatus(void); 56 | FunctionalState IRTIM_GetHighSinkODStatus(void); 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | #endif /* __STM8L15x_IRTIM_H */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 69 | -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/inc/stm8l15x_rst.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8l15x_rst.h 4 | * @author MCD Application Team 5 | * @version V1.6.1 6 | * @date 30-September-2014 7 | * @brief This file contains all the functions prototypes for the RST firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8L15x_RST_H 31 | #define __STM8L15x_RST_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8l15x.h" 35 | 36 | /** @addtogroup STM8L15x_StdPeriph_Driver 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup RST 41 | * @{ 42 | */ 43 | 44 | /* Exported variables ------------------------------------------------------- */ 45 | /* Exported types ------------------------------------------------------------*/ 46 | /** @defgroup RST_Exported_Types 47 | * @{ 48 | */ 49 | 50 | /** @defgroup RST_Flags 51 | * @{ 52 | */ 53 | typedef enum { 54 | RST_FLAG_PORF = (uint8_t)0x01, /*!< POR reset flag */ 55 | RST_FLAG_SWIMF = (uint8_t)0x08, /*!< SWIM reset flag */ 56 | RST_FLAG_ILLOPF = (uint8_t)0x04, /*!< Illegal opcode reset flag */ 57 | RST_FLAG_IWDGF = (uint8_t)0x02, /*!< Independent watchdog reset flag */ 58 | RST_FLAG_WWDGF = (uint8_t)0x10, /*!< Window watchdog reset flag */ 59 | RST_FLAG_BORF = (uint8_t)0x20 /*!< BOR reset flag */ 60 | } RST_FLAG_TypeDef; 61 | 62 | #define IS_RST_FLAG(FLAG) (((FLAG) == RST_FLAG_PORF) || ((FLAG) == RST_FLAG_BORF) || \ 63 | ((FLAG) == RST_FLAG_IWDGF) || ((FLAG) == RST_FLAG_ILLOPF) || \ 64 | ((FLAG) == RST_FLAG_WWDGF) || ((FLAG) == RST_FLAG_SWIMF)) 65 | /** 66 | * @} 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | /* Exported constants --------------------------------------------------------*/ 73 | /* Exported macros -----------------------------------------------------------*/ 74 | /* Exported functions ------------------------------------------------------- */ 75 | /* Flag management functions **************************************************/ 76 | FlagStatus RST_GetFlagStatus(RST_FLAG_TypeDef RST_Flag); 77 | void RST_ClearFlag(RST_FLAG_TypeDef RST_Flag); 78 | 79 | /* NRST Pin configuration function ********************************************/ 80 | void RST_GPOutputEnable(void); 81 | 82 | #endif /* __STM8L15x_RST_H */ 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/inc/stm8l15x_rtc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/inc/stm8l15x_rtc.h -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/inc/stm8l15x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8l15x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.6.1 6 | * @date 30-September-2014 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM8L15x_WWDG_H 31 | #define __STM8L15x_WWDG_H 32 | 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm8l15x.h" 35 | 36 | /** @addtogroup STM8L15x_StdPeriph_Driver 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup WWDG 41 | * @{ 42 | */ 43 | 44 | /* Exported types ------------------------------------------------------------*/ 45 | /* Exported constants --------------------------------------------------------*/ 46 | /* Exported macro ------------------------------------------------------------*/ 47 | 48 | /** @defgroup WWDG_Exported_Macros 49 | * @{ 50 | */ 51 | 52 | /** @defgroup WWDG_WindowLimitValue 53 | * @{ 54 | */ 55 | #define IS_WWDG_WINDOW_LIMIT_VALUE(WindowLimitValue) ((WindowLimitValue) <= 0x7F) 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup WWDG_CounterValue 62 | * @{ 63 | */ 64 | #define IS_WWDG_COUNTER_VALUE(CounterValue) ((CounterValue) <= 0x7F) 65 | /** 66 | * @} 67 | */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /* Exported functions ------------------------------------------------------- */ 74 | /* Refresh window and Counter configuration functions *************************/ 75 | void WWDG_Init(uint8_t Counter, uint8_t WindowValue); 76 | void WWDG_SetWindowValue(uint8_t WindowValue); 77 | void WWDG_SetCounter(uint8_t Counter); 78 | 79 | /* WWDG activation function ***************************************************/ 80 | void WWDG_Enable(uint8_t Counter); 81 | 82 | /* WWDG counter and software reset management **********************************/ 83 | uint8_t WWDG_GetCounter(void); 84 | void WWDG_SWReset(void); 85 | 86 | 87 | #endif /* __STM8L15x_WWDG_H */ 88 | /** 89 | * @} 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_adc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_adc.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_comp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_comp.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_dma.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_dma.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_flash.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_i2c.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_rst.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_rst.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim1.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim2.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim3.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim4.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim5.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_tim5.c -------------------------------------------------------------------------------- /system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Lxx_StdPeriph_Driver/src/stm8l15x_usart.c -------------------------------------------------------------------------------- /system/Drivers/STM8Sxx_StdPeriph_Driver/Release_Notes.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/Arduino_Core_STM8/cc4d30f28145a4778dfe228856e6ea48b00390b5/system/Drivers/STM8Sxx_StdPeriph_Driver/Release_Notes.html -------------------------------------------------------------------------------- /system/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s_rst.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_rst.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the RST peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __STM8S_RST_H 29 | #define __STM8S_RST_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm8s.h" 33 | 34 | /** @addtogroup STM8S_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RST_Exported_Types 39 | * @{ 40 | */ 41 | typedef enum { 42 | RST_FLAG_EMCF = (uint8_t)0x10, /*!< EMC reset flag */ 43 | RST_FLAG_SWIMF = (uint8_t)0x08, /*!< SWIM reset flag */ 44 | RST_FLAG_ILLOPF = (uint8_t)0x04, /*!< Illigal opcode reset flag */ 45 | RST_FLAG_IWDGF = (uint8_t)0x02, /*!< Independent watchdog reset flag */ 46 | RST_FLAG_WWDGF = (uint8_t)0x01 /*!< Window watchdog reset flag */ 47 | }RST_Flag_TypeDef; 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Exported macros -----------------------------------------------------------*/ 55 | 56 | /** @addtogroup RST_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @brief Macro used by the assert function to check the different functions parameters. 62 | */ 63 | /** 64 | * @brief Macro used by the assert function to check the different RST flags. 65 | */ 66 | #define IS_RST_FLAG_OK(FLAG) (((FLAG) == RST_FLAG_EMCF) || \ 67 | ((FLAG) == RST_FLAG_SWIMF) ||\ 68 | ((FLAG) == RST_FLAG_ILLOPF) ||\ 69 | ((FLAG) == RST_FLAG_IWDGF) ||\ 70 | ((FLAG) == RST_FLAG_WWDGF)) 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @addtogroup RST_Exported_functions 77 | * @{ 78 | */ 79 | FlagStatus RST_GetFlagStatus(RST_Flag_TypeDef RST_Flag); 80 | void RST_ClearFlag(RST_Flag_TypeDef RST_Flag); 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | #endif /* __STM8S_RST_H */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 93 | -------------------------------------------------------------------------------- /system/Drivers/STM8Sxx_StdPeriph_Driver/inc/stm8s_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ******************************************************************************** 3 | * @file stm8s_wwdg.h 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all functions prototype and macros for the WWDG peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM8S_WWDG_H 30 | #define __STM8S_WWDG_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm8s.h" 34 | 35 | /** @addtogroup STM8S_StdPeriph_Driver 36 | * @{ 37 | */ 38 | 39 | /* Private macros ------------------------------------------------------------*/ 40 | 41 | /** @addtogroup WWDG_Private_Macros 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief Macro used by the assert function in order to check the 47 | * values of the window register. 48 | */ 49 | #define IS_WWDG_WINDOWLIMITVALUE_OK(WindowLimitValue) ((WindowLimitValue) <= 0x7F) 50 | 51 | /** 52 | * @brief Macro used by the assert function in order to check the different 53 | * values of the counter register. 54 | */ 55 | #define IS_WWDG_COUNTERVALUE_OK(CounterValue) ((CounterValue) <= 0x7F) 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /* Exported types ------------------------------------------------------------*/ 62 | 63 | /* Exported functions ------------------------------------------------------- */ 64 | 65 | /** @addtogroup WWDG_Exported_Functions 66 | * @{ 67 | */ 68 | 69 | void WWDG_Init(uint8_t Counter, uint8_t WindowValue); 70 | void WWDG_SetCounter(uint8_t Counter); 71 | uint8_t WWDG_GetCounter(void); 72 | void WWDG_SWReset(void); 73 | void WWDG_SetWindowValue(uint8_t WindowValue); 74 | 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | #endif /* __STM8S_WWDG_H */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /system/Drivers/STM8Sxx_StdPeriph_Driver/src/stm8s_rst.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm8s_rst.c 4 | * @author MCD Application Team 5 | * @version V2.3.0 6 | * @date 16-June-2017 7 | * @brief This file contains all the functions for the RST peripheral. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | 30 | #include "stm8s_rst.h" 31 | 32 | /** @addtogroup STM8S_StdPeriph_Driver 33 | * @{ 34 | */ 35 | /* Private typedef -----------------------------------------------------------*/ 36 | /* Private define ------------------------------------------------------------*/ 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* Private variables ---------------------------------------------------------*/ 39 | /* Private function prototypes -----------------------------------------------*/ 40 | /* Private Constants ---------------------------------------------------------*/ 41 | /* Public functions ----------------------------------------------------------*/ 42 | /** 43 | * @addtogroup RST_Public_Functions 44 | * @{ 45 | */ 46 | 47 | 48 | /** 49 | * @brief Checks whether the specified RST flag is set or not. 50 | * @param RST_Flag : specify the reset flag to check. 51 | * This parameter can be a value of @ref RST_Flag_TypeDef. 52 | * @retval FlagStatus: status of the given RST flag. 53 | */ 54 | FlagStatus RST_GetFlagStatus(RST_Flag_TypeDef RST_Flag) 55 | { 56 | /* Check the parameters */ 57 | assert_param(IS_RST_FLAG_OK(RST_Flag)); 58 | 59 | /* Get flag status */ 60 | return((FlagStatus)(((uint8_t)(RST->SR & RST_Flag) == (uint8_t)0x00) ? RESET : SET)); 61 | } 62 | 63 | /** 64 | * @brief Clears the specified RST flag. 65 | * @param RST_Flag : specify the reset flag to clear. 66 | * This parameter can be a value of @ref RST_Flag_TypeDef. 67 | * @retval None 68 | */ 69 | void RST_ClearFlag(RST_Flag_TypeDef RST_Flag) 70 | { 71 | /* Check the parameters */ 72 | assert_param(IS_RST_FLAG_OK(RST_Flag)); 73 | 74 | RST->SR = (uint8_t)RST_Flag; 75 | } 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /variants/NUCLEO_8L152R8/lkfscript.lkf: -------------------------------------------------------------------------------- 1 | # link command file for STM8S105C6 2 | # Copyright (c) 2017 by COSMIC Software 3 | # 4 | +seg .vector -b0x8000 -m0x8000 -n .vector -cs code -k # interrupt and rest vectors 5 | +seg .const -a .vector -n .const # constants follow vectors 6 | +seg ._construct_ -a .const -n .construct -k # constructor table 7 | +seg .text -a .construct -n .text # code follow constants 8 | +seg .eeprom -b 0x1000 -m 0x800 -cs eeprom # internal eeprom 9 | +seg .bsct -b 0x0 -m 0x100 -n .bsct -cs data # internal ram 10 | +seg .ubsct -a .bsct -n .ubsct 11 | +seg .bit -a .ubsct -n .bit -id 12 | +seg .data -a .bit -m 0xcff -n .data 13 | +seg .bss -a .data -n .bss 14 | crtspi0.sm8 15 | @* 16 | libcppsl0.sm8 17 | libfsl0.sm8 18 | libisl0.sm8 19 | libll.sm8 20 | libm0.sm8 21 | +def __memory=@.bss 22 | +def __endzp=@.ubsct 23 | +def __stack=0xfff 24 | +def __startmem=@.bss 25 | +def __endmem=0xdfe 26 | +def __ctorstart=start(.construct) 27 | +def __ctorend=end(.construct) -------------------------------------------------------------------------------- /variants/NUCLEO_8S208RB/lkfscript.lkf: -------------------------------------------------------------------------------- 1 | # link command file for STM8S105C6 2 | # Copyright (c) 2017 by COSMIC Software 3 | # 4 | +seg .vector -b0x8000 -m0x8000 -n .vector -cs code -k # interrupt and rest vectors 5 | +seg .const -a .vector -n .const # constants follow vectors 6 | +seg ._construct_ -a .const -n .construct -k # constructor table 7 | +seg .text -a .construct -n .text # code follow constants 8 | +seg .eeprom -b 0x4000 -m 0x800 -cs eeprom # internal eeprom 9 | +seg .bsct -b 0x0 -m 0x100 -n .bsct -cs data # internal ram 10 | +seg .ubsct -a .bsct -n .ubsct 11 | +seg .bit -a .ubsct -n .bit -id 12 | +seg .data -a .bit -m 0x1300 -n .data 13 | +seg .bss -a .data -n .bss 14 | crtspi0.sm8 15 | @* 16 | libcppsl0.sm8 17 | libfsl0.sm8 18 | libisl0.sm8 19 | libll.sm8 20 | libm0.sm8 21 | +def __memory=@.bss 22 | +def __endzp=@.ubsct 23 | +def __stack=0x17ff 24 | +def __startmem=@.bss 25 | +spc .bss=0x100 26 | +def __endmem=@.bss 27 | +def __ctorstart=start(.construct) 28 | +def __ctorend=end(.construct) --------------------------------------------------------------------------------