From 04f06bd7df39bd082fddae02ff572b0276a39300 Mon Sep 17 00:00:00 2001 From: alfran Date: Tue, 14 Mar 2017 11:46:27 +0100 Subject: [PATCH 1/2] code cleanup --- cores/arduino/Arduino.h | 18 ++- cores/arduino/SPI.h | 5 + cores/arduino/WCharacter.h | 1 - cores/arduino/dac.c | 3 +- cores/arduino/delay.h | 19 ++- cores/arduino/rcc.c | 5 +- variants/otto/variant.cpp | 256 ++++++++++++------------------------- variants/otto/variant.h | 192 +++++++++++++++++----------- 8 files changed, 240 insertions(+), 259 deletions(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index fcc4912..af99be3 100755 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -1,5 +1,21 @@ -// to add license +/* + Arduino.h - Main include file for the Arduino SDK + Copyright (c) 2005-2013 Arduino Team. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ /* * Arduino srl diff --git a/cores/arduino/SPI.h b/cores/arduino/SPI.h index c72315f..457754a 100644 --- a/cores/arduino/SPI.h +++ b/cores/arduino/SPI.h @@ -11,6 +11,11 @@ * published by the Free Software Foundation. */ + /* + * Arduino srl - www.arduino.org + * 2016 Jun 9: Edited Francesco Alessi (alfran) - francesco@arduino.org + */ + #ifndef _SPI_H_INCLUDED #define _SPI_H_INCLUDED diff --git a/cores/arduino/WCharacter.h b/cores/arduino/WCharacter.h index 167cf17..3781bec 100644 --- a/cores/arduino/WCharacter.h +++ b/cores/arduino/WCharacter.h @@ -19,7 +19,6 @@ #ifndef Character_h #define Character_h -//ciao #include // WCharacter.h prototypes diff --git a/cores/arduino/dac.c b/cores/arduino/dac.c index 81b5957..2a242c2 100755 --- a/cores/arduino/dac.c +++ b/cores/arduino/dac.c @@ -79,7 +79,7 @@ void dac_init(const dac_dev *dev, uint32 flags) { * DAC_CH1: Select channel 1 * DAC_CH2: Select channel 2 * @param status Status: - * 1: enable buffer + * 1: enable buffer * 0: disable buffer */ void dac_enable_buffer(const dac_dev *dev, uint32 flags, int status) { @@ -124,7 +124,6 @@ void dac_write_channel(const dac_dev *dev, uint8 channel, uint16 val) { * @brief Enable a DAC channel * @param dev DAC device * @param channel channel to enable, either 1 or 2 - * @sideeffect May change pin mode of PA4 or PA5 */ void dac_enable_channel(const dac_dev *dev, uint8 channel) { /* diff --git a/cores/arduino/delay.h b/cores/arduino/delay.h index 9382fae..997ce6c 100755 --- a/cores/arduino/delay.h +++ b/cores/arduino/delay.h @@ -1,3 +1,21 @@ +/* + Copyright (c) 2014 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + /** * @file delay.h * @brief Delay implementation @@ -41,4 +59,3 @@ static inline void delay_ns100(uint32 us) { : "r0"); } #endif - diff --git a/cores/arduino/rcc.c b/cores/arduino/rcc.c index 71bb788..74d64a3 100755 --- a/cores/arduino/rcc.c +++ b/cores/arduino/rcc.c @@ -223,7 +223,7 @@ void InitMCO1() gpio_set_mode(GPIOA_dev, 8, GPIO_MODE_AF | GPIO_OTYPE_PP | GPIO_OSPEED_100MHZ); } -void SetupClock() // to be setted properly +void SetupClock() { RCC_ClkInitTypeDef RCC_ClkInitStruct; @@ -302,9 +302,6 @@ void SetupClock() // to be setted properly rcc_dev_clk_speed_table[RCC_APB1] = (SystemCoreClock/4); } -// alfran ----- end - - void rcc_clk_init(rcc_sysclk_src sysclk_src, rcc_pllsrc pll_src, rcc_pll_multiplier pll_mul) { diff --git a/variants/otto/variant.cpp b/variants/otto/variant.cpp index 3721765..a7d3788 100644 --- a/variants/otto/variant.cpp +++ b/variants/otto/variant.cpp @@ -40,201 +40,109 @@ * 2016 Dec 20: Modified for HW rev 3 */ -//#include "otto.h" #include "variant.h" - #include "gpio.h" #include "rcc.h" #include "timer.h" - #include "wiring_types.h" -/* alfran: commented for new pin management -void boardInit(void) -{ - - // PWM output setting - // D0...D13 - gpio_set_af_mode(GPIOA, 1, 2); // D00 - TIM5_CH2 - gpio_set_af_mode(GPIOA, 0, 2); // D01 - TIM5_CH1 - gpio_set_af_mode(GPIOH, 6, 9); // D02 - TIM12_CH1 - gpio_set_af_mode(GPIOB, 15, 9); // D03 - TIM12_CH2 - gpio_set_af_mode(GPIOC, 7, 3); // D04 - TIM8_CH2 - gpio_set_af_mode(GPIOC, 6, 3); // D05 - TIM8_CH1 - gpio_set_af_mode(GPIOD, 13, 2); // D06 - TIM4_CH2 - gpio_set_af_mode(GPIOD, 12, 2); // D07 - TIM4_CH1 - gpio_set_af_mode(GPIOA, 8, 1); // D08 - TIM1_CH1 - gpio_set_af_mode(GPIOA, 9, 1); // D09 - TIM1_CH2 - gpio_set_af_mode(GPIOA, 15, 1); // D10 - TIM2_CH1 - gpio_set_af_mode(GPIOB, 5, 2); // D11 - TIM3_CH2 - gpio_set_af_mode(GPIOB, 4, 2); // D12 - TIM3_CH1 - gpio_set_af_mode(GPIOB, 3, 1); // D13 - TIM2_CH2 - - // D14...D21 - //gpio_set_af_mode(GPIOG, 14, ); // D14 - TIM_CH - //gpio_set_af_mode(GPIOG, 9, ); // D15 - TIM_CH - //gpio_set_af_mode(GPIOD, 5, ); // D16 - TIM_CH - //gpio_set_af_mode(GPIOD, 6, ); // D17 - TIM_CH - gpio_set_af_mode(GPIOB, 10, 1); // D18 - TIM2_CH3 - gpio_set_af_mode(GPIOB, 11, 1); // D19 - TIM2_CH4 - //gpio_set_af_mode(GPIOH, 5, ); // D20 - TIM_CH - //gpio_set_af_mode(GPIOH, 4, ); // D21 - TIM_CH - - // D22...D53 - //gpio_set_af_mode(GPIOJ, 3, ); // D22 - TIM_CH - //gpio_set_af_mode(GPIOG, 11, ); // D23 - TIM_CH - //gpio_set_af_mode(GPIOE, 2, ); // D24 - TIM_CH - //gpio_set_af_mode(GPIOE, 4, ); // D25 - TIM_CH - //gpio_set_af_mode(GPIOI, 8, ); // D26 - TIM_CH - //gpio_set_af_mode(GPIOC, 13, ); // D27 - TIM_CH - //gpio_set_af_mode(GPIOI, 11, ); // D28 - TIM_CH - //gpio_set_af_mode(GPIOI, 12, ); // D29 - TIM_CH - //gpio_set_af_mode(GPIOI, 13, ); // D30 - TIM_CH - //gpio_set_af_mode(GPIOI, 14, ); // D31 - TIM_CH - //gpio_set_af_mode(GPIOI, 15, ); // D32 - TIM_CH - //gpio_set_af_mode(GPIOJ, 0, ); // D33 - TIM_CH - //gpio_set_af_mode(GPIOJ, 1, ); // D34 - TIM_CH - //gpio_set_af_mode(GPIOI, 10, ); // D35 - TIM_CH - //gpio_set_af_mode(GPIOK, 3, ); // D36 - TIM_CH - //gpio_set_af_mode(GPIOJ, 4, ); // D37 - TIM_CH - //gpio_set_af_mode(GPIOK, 5, ); // D38 - TIM_CH - //gpio_set_af_mode(GPIOJ, 5, ); // D39 - TIM_CH - //gpio_set_af_mode(GPIOD, 11, ); // D40 - TIM_CH - //gpio_set_af_mode(GPIOG, 2, ); // D41 - TIM_CH - //gpio_set_af_mode(GPIOG, 3, ); // D42 - TIM_CH - //gpio_set_af_mode(GPIOG, 6, ); // D43 - TIM_CH - //gpio_set_af_mode(GPIOG, 7, ); // D44 - TIM_CH - //gpio_set_af_mode(GPIOD, 4, ); // D45 - TIM_CH - //gpio_set_af_mode(GPIOJ, 12, ); // D46 - TIM_CH - //gpio_set_af_mode(GPIOJ, 13, ); // D47 - TIM_CH - //gpio_set_af_mode(GPIOJ, 14, ); // D48 - TIM_CH - //gpio_set_af_mode(GPIOJ, 15, ); // D49 - TIM_CH - //gpio_set_af_mode(GPIOG, 12, ); // D50 - TIM_CH - gpio_set_af_mode(GPIOB, 13, 1); // D51 - TIM1_CH1N - //gpio_set_af_mode(GPIOG, 13, ); // D52 - TIM_CH - //gpio_set_af_mode(GPIOB, 12, ); // D53 - TIM_CH - - // A0...A11 (D54...D65) - gpio_set_af_mode(GPIOB, 0, 2); // D54 - TIM3_CH3 - gpio_set_af_mode(GPIOB, 1, 2); // D55 - TIM3_CH4 - gpio_set_af_mode(GPIOF, 6, 3); // D56 - TIM10_CH1 - //gpio_set_af_mode(GPIOC, 5, ); // D57 - TIM_CH - gpio_set_af_mode(GPIOA, 3, 2); // D58 - TIM5_CH4 - gpio_set_af_mode(GPIOA, 2, 2); // D59 - TIM5_CH3 - //gpio_set_af_mode(GPIOF, 10, ); // D60 - TIM_CH - //gpio_set_af_mode(GPIOA, 7, ); // D61 - TIM_CH - //gpio_set_af_mode(GPIOC, 2, ); // D62 - TIM_CH - //gpio_set_af_mode(GPIOC, 4, ); // D63 - TIM_CH - gpio_set_af_mode(GPIOF, 7, 3); // D64 - TIM11_CH1 - //gpio_set_af_mode(GPIOC, 1, ); // D65 - TIM_CH - - // DAC0 - DAC1 (D66 - D67) - //gpio_set_af_mode(GPIOA, 4, ); // D66 - TIM_CH - gpio_set_af_mode(GPIOA, 5, 3); // D67 - TIM8_CH1N - - // CANRX - CANTX (D68 - D69) - gpio_set_af_mode(GPIOB, 8, 2); // D68 - TIM4_CH3 - gpio_set_af_mode(GPIOB, 9, 2); // D69 - TIM4_CH4 - - - return; -} -*/ extern const stm32_pin_info PIN_MAP[GPIO_PINS] = { - // GPIO BIT TIMER TIM_CH AF ADC ADC_CH // D0...D13 NAME - IRQ - TIMER - ADC - ALTERNATE - - {GPIOA_dev, 1, TIMER5, 2, 2, NULL, ADCx}, // PA1: D00 - - TIM2_CH2/TIM5_CH2 - ADC123_IN1 - UART4_RX (Serial0) - - {GPIOA_dev, 0, TIMER5, 1, 2, NULL, ADCx}, // PA0: D01 - - TIM2_CH1/TIM5_CH1 - ADC123_IN0 - UART4_TX (Serial0) - - {GPIOH_dev, 6, TIMER12, 1, 9, NULL, ADCx}, // PH6: D02 - - TIM12_CH1 - - - {GPIOB_dev, 15, TIMER12, 2, 9, NULL, ADCx}, // PB15: D03 - - TIM1_CH3N/TIM8_CH3N/TIM12_CH2 - - - {GPIOC_dev, 7, TIMER8, 2, 3, NULL, ADCx}, // PC7: D04 - - TIM3_CH2/TIM8_CH2 - - - {GPIOC_dev, 6, TIMER8, 1, 3, NULL, ADCx}, // PC6: D05 - - TIM3_CH1/TIM8_CH1 - - - {GPIOD_dev, 13, TIMER4, 2, 2, NULL, ADCx}, // PD13: D06 - - TIM4_CH2 - - - {GPIOD_dev, 12, TIMER4, 1, 2, NULL, ADCx}, // PD12: D07 - - TIM4_CH1 - - - {GPIOA_dev, 8, TIMER1, 1, 1, NULL, ADCx}, // PA8: D08 - - TIM1_CH1 - - - {GPIOA_dev, 9, TIMER1, 2, 1, NULL, ADCx}, // PA9: D09 - - TIM1_CH2 - - - {GPIOA_dev, 15, TIMER2, 1, 1, NULL, ADCx}, // PA15: D10 - - TIM2_CH1 - - SPI1_NSS - {GPIOB_dev, 5, TIMER3, 2, 2, NULL, ADCx}, // PB5: D11 - - TIM3_CH2 - - SPI1_MOSI - {GPIOB_dev, 4, TIMER3, 1, 2, NULL, ADCx}, // PB4: D12 - - TIM3_CH1 - - SPI1_MISO - {GPIOB_dev, 3, TIMER2, 2, 1, NULL, ADCx}, // PB3: D13 - - TIM2_CH2 - - SPI1_SCK + {GPIOA_dev, 1, TIMER5, 2, 2, NULL, ADCx}, // PA1: D00 - - TIM2_CH2/TIM5_CH2 - ADC123_IN1 - UART4_RX (Serial0) - + {GPIOA_dev, 0, TIMER5, 1, 2, NULL, ADCx}, // PA0: D01 - - TIM2_CH1/TIM5_CH1 - ADC123_IN0 - UART4_TX (Serial0) - + {GPIOH_dev, 6, TIMER12, 1, 9, NULL, ADCx}, // PH6: D02 - - TIM12_CH1 - - + {GPIOB_dev, 15, TIMER12, 2, 9, NULL, ADCx}, // PB15: D03 - - TIM1_CH3N/TIM8_CH3N/TIM12_CH2 - - + {GPIOC_dev, 7, TIMER8, 2, 3, NULL, ADCx}, // PC7: D04 - - TIM3_CH2/TIM8_CH2 - - + {GPIOC_dev, 6, TIMER8, 1, 3, NULL, ADCx}, // PC6: D05 - - TIM3_CH1/TIM8_CH1 - - + {GPIOD_dev, 13, TIMER4, 2, 2, NULL, ADCx}, // PD13: D06 - - TIM4_CH2 - - + {GPIOD_dev, 12, TIMER4, 1, 2, NULL, ADCx}, // PD12: D07 - - TIM4_CH1 - - + {GPIOA_dev, 8, TIMER1, 1, 1, NULL, ADCx}, // PA8: D08 - - TIM1_CH1 - - + {GPIOA_dev, 9, TIMER1, 2, 1, NULL, ADCx}, // PA9: D09 - - TIM1_CH2 - - + {GPIOA_dev, 15, TIMER2, 1, 1, NULL, ADCx}, // PA15: D10 - - TIM2_CH1 - - SPI1_NSS + {GPIOB_dev, 5, TIMER3, 2, 2, NULL, ADCx}, // PB5: D11 - - TIM3_CH2 - - SPI1_MOSI + {GPIOB_dev, 4, TIMER3, 1, 2, NULL, ADCx}, // PB4: D12 - - TIM3_CH1 - - SPI1_MISO + {GPIOB_dev, 3, TIMER2, 2, 1, NULL, ADCx}, // PB3: D13 - - TIM2_CH2 - - SPI1_SCK // D14...D21 - {GPIOG_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PG14: D14 - - - - USART6_TX (Serial3) - - {GPIOG_dev, 9, NULL, 0, AFx, NULL, ADCx}, // PG9: D15 - - - - USART6_RX (Serial3) - - {GPIOD_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PD5: D16 - - - - USART2_TX (Serial2) - - {GPIOD_dev, 6, NULL, 0, AFx, NULL, ADCx}, // PD6: D17 - - - - USART2_RX (Serial2) - - {GPIOB_dev, 10, TIMER2, 3, 1, NULL, ADCx}, // PB10: D18 - - TIM2_CH3 - - USART3_TX (Serial1) - - {GPIOB_dev, 11, TIMER2, 4, 1, NULL, ADCx}, // PB11: D19 - - TIM2_CH4 - - USART3_RX (Serial1) - - {GPIOH_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PH5: D20 - - - - I2C2_SDA - - {GPIOH_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PH4: D21 - - - - I2C2_SCL - + {GPIOG_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PG14: D14 - - - - USART6_TX (Serial3) - + {GPIOG_dev, 9, NULL, 0, AFx, NULL, ADCx}, // PG9: D15 - - - - USART6_RX (Serial3) - + {GPIOD_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PD5: D16 - - - - USART2_TX (Serial2) - + {GPIOD_dev, 6, NULL, 0, AFx, NULL, ADCx}, // PD6: D17 - - - - USART2_RX (Serial2) - + {GPIOB_dev, 10, TIMER2, 3, 1, NULL, ADCx}, // PB10: D18 - - TIM2_CH3 - - USART3_TX (Serial1) - + {GPIOB_dev, 11, TIMER2, 4, 1, NULL, ADCx}, // PB11: D19 - - TIM2_CH4 - - USART3_RX (Serial1) - + {GPIOH_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PH5: D20 - - - - I2C2_SDA - + {GPIOH_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PH4: D21 - - - - I2C2_SCL - // D22...D53 - {GPIOJ_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PE5: D22 - - - - - {GPIOG_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PE6: D23 - - - - - {GPIOE_dev, 2, NULL, 0, AFx, NULL, ADCx}, // PE2: D24 - - - - - {GPIOE_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PE4: D25 - - - - - {GPIOI_dev, 8, NULL, 0, AFx, NULL, ADCx}, // PI8: D26 - - - - - {GPIOC_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PC13: D27 - - - - - {GPIOI_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PI11: D28 - - - - - {GPIOI_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PI12: D29 - - - - - {GPIOI_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PI13: D30 - - - - - {GPIOI_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PI14: D31 - - - - - {GPIOI_dev, 15, NULL, 0, AFx, NULL, ADCx}, // PI15: D32 - - - - - {GPIOJ_dev, 0, NULL, 0, AFx, NULL, ADCx}, // PJ0: D33 - - - - - {GPIOJ_dev, 1, NULL, 0, AFx, NULL, ADCx}, // PJ1: D34 - - - - - {GPIOI_dev, 10, NULL, 0, AFx, NULL, ADCx}, // PI10: D35 - - - - - {GPIOK_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PK3: D36 - - - - - {GPIOJ_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PJ4: D37 - - - - - {GPIOK_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PK5: D38 - - - - - {GPIOJ_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PJ5: D39 - - - - - {GPIOD_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PD11: D40 - - - - - {GPIOG_dev, 2, NULL, 0, AFx, NULL, ADCx}, // PG2: D41 - - - - - {GPIOG_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PG3: D42 - - - - - {GPIOG_dev, 6, NULL, 0, AFx, NULL, ADCx}, // PG6: D43 - - - - - {GPIOG_dev, 7, NULL, 0, AFx, NULL, ADCx}, // PG7: D44 - - - - - {GPIOD_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PD4: D45 - - - - - {GPIOJ_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PJ12: D46 - - - - - {GPIOJ_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PJ13: D47 - - - - - {GPIOJ_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PJ14: D48 - - - - - {GPIOJ_dev, 15, NULL, 0, AFx, NULL, ADCx}, // PJ15: D49 - - - - - {GPIOG_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PG12: D50 - - - - - {GPIOB_dev, 13, TIMER1, 5, 1, NULL, ADCx}, // PB13: D51 - - TIM1_CH1N - - - {GPIOG_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PG13: D52 - - - - - {GPIOB_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PB12: D53 - - - - + {GPIOJ_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PE5: D22 - - - - + {GPIOG_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PE6: D23 - - - - + {GPIOE_dev, 2, NULL, 0, AFx, NULL, ADCx}, // PE2: D24 - - - - + {GPIOE_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PE4: D25 - - - - + {GPIOI_dev, 8, NULL, 0, AFx, NULL, ADCx}, // PI8: D26 - - - - + {GPIOC_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PC13: D27 - - - - + {GPIOI_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PI11: D28 - - - - + {GPIOI_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PI12: D29 - - - - + {GPIOI_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PI13: D30 - - - - + {GPIOI_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PI14: D31 - - - - + {GPIOI_dev, 15, NULL, 0, AFx, NULL, ADCx}, // PI15: D32 - - - - + {GPIOJ_dev, 0, NULL, 0, AFx, NULL, ADCx}, // PJ0: D33 - - - - + {GPIOJ_dev, 1, NULL, 0, AFx, NULL, ADCx}, // PJ1: D34 - - - - + {GPIOI_dev, 10, NULL, 0, AFx, NULL, ADCx}, // PI10: D35 - - - - + {GPIOK_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PK3: D36 - - - - + {GPIOJ_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PJ4: D37 - - - - + {GPIOK_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PK5: D38 - - - - + {GPIOJ_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PJ5: D39 - - - - + {GPIOD_dev, 11, NULL, 0, AFx, NULL, ADCx}, // PD11: D40 - - - - + {GPIOG_dev, 2, NULL, 0, AFx, NULL, ADCx}, // PG2: D41 - - - - + {GPIOG_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PG3: D42 - - - - + {GPIOG_dev, 6, NULL, 0, AFx, NULL, ADCx}, // PG6: D43 - - - - + {GPIOG_dev, 7, NULL, 0, AFx, NULL, ADCx}, // PG7: D44 - - - - + {GPIOD_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PD4: D45 - - - - + {GPIOJ_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PJ12: D46 - - - - + {GPIOJ_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PJ13: D47 - - - - + {GPIOJ_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PJ14: D48 - - - - + {GPIOJ_dev, 15, NULL, 0, AFx, NULL, ADCx}, // PJ15: D49 - - - - + {GPIOG_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PG12: D50 - - - - + {GPIOB_dev, 13, TIMER1, 5, 1, NULL, ADCx}, // PB13: D51 - - TIM1_CH1N - - + {GPIOG_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PG13: D52 - - - - + {GPIOB_dev, 12, NULL, 0, AFx, NULL, ADCx}, // PB12: D53 - - - - // A0...A11 (D54...D65) - {GPIOB_dev, 0, TIMER3, 3, 2, ADC1_dev, 8}, // PB0: D54 / A0 - INT - TIM1_CH2N/TIM3_CH3/TIM8_CH2N - ADC12_IN8 - - {GPIOB_dev, 1, TIMER3, 4, 2, ADC1_dev, 9}, // PB1: D55 / A1 - INT - TIM1_CH3N/TIM3_CH4/TIM8_CH3N - ADC12_IN9 - - {GPIOF_dev, 6, TIMER10, 1, 3, ADC3_dev, 4}, // PF6: D56 / A2 - INT - TIM10_CH1 - ADC3_IN4 - - {GPIOC_dev, 5, NULL, 0, AFx, ADC1_dev, 15}, // PC5: D57 / A3 - INT - - ADC12_IN15 - - {GPIOA_dev, 3, TIMER5, 4, 2, ADC3_dev, 3}, // PA3: D58 / A4 - - TIM2_CH4/TIM5_CH4/TIM9_CH2 - ADC123_IN3 - - {GPIOA_dev, 2, TIMER5, 3, 2, ADC2_dev, 2}, // PA2: D59 / A5 - INT - TIM2_CH3/TIM5_CH3/TIM9_CH1 - ADC123_IN1 - - {GPIOF_dev, 10, NULL, 0, AFx, ADC3_dev, 8}, // PF10: D60 / A6 - INT - - ADC3_IN8 - - {GPIOA_dev, 7, NULL, 0, AFx, ADC1_dev, 7}, // PA7: D61 / A7 - INT - TIM1_CH1N/TIM3_CH1/TIM8_CH1N - ADC12_IN - - {GPIOC_dev, 2, NULL, 0, AFx, ADC2_dev, 12}, // PC2: D62 / A8 - INT - - ADC123_IN12 - - {GPIOC_dev, 4, NULL, 0, AFx, ADC1_dev, 14}, // PC4: D63 / A9 - - - ADC12_IN14 - - {GPIOF_dev, 7, TIMER11, 1, 3, ADC3_dev, 5}, // PF7: D64 / A10 - - TIM11_CH1 - ADC3_IN5 - - {GPIOC_dev, 1, NULL, 0, AFx, ADC3_dev, 11}, // PC1: D65 / A11 - - - ADC123_IN11 - + {GPIOB_dev, 0, TIMER3, 3, 2, ADC1_dev, 8}, // PB0: D54 / A0 - INT - TIM1_CH2N/TIM3_CH3/TIM8_CH2N - ADC12_IN8 - + {GPIOB_dev, 1, TIMER3, 4, 2, ADC1_dev, 9}, // PB1: D55 / A1 - INT - TIM1_CH3N/TIM3_CH4/TIM8_CH3N - ADC12_IN9 - + {GPIOF_dev, 6, TIMER10, 1, 3, ADC3_dev, 4}, // PF6: D56 / A2 - INT - TIM10_CH1 - ADC3_IN4 - + {GPIOC_dev, 5, NULL, 0, AFx, ADC1_dev, 15}, // PC5: D57 / A3 - INT - - ADC12_IN15 - + {GPIOA_dev, 3, TIMER5, 4, 2, ADC3_dev, 3}, // PA3: D58 / A4 - - TIM2_CH4/TIM5_CH4/TIM9_CH2 - ADC123_IN3 - + {GPIOA_dev, 2, TIMER5, 3, 2, ADC2_dev, 2}, // PA2: D59 / A5 - INT - TIM2_CH3/TIM5_CH3/TIM9_CH1 - ADC123_IN1 - + {GPIOF_dev, 10, NULL, 0, AFx, ADC3_dev, 8}, // PF10: D60 / A6 - INT - - ADC3_IN8 - + {GPIOA_dev, 7, NULL, 0, AFx, ADC1_dev, 7}, // PA7: D61 / A7 - INT - TIM1_CH1N/TIM3_CH1/TIM8_CH1N - ADC12_IN - + {GPIOC_dev, 2, NULL, 0, AFx, ADC2_dev, 12}, // PC2: D62 / A8 - INT - - ADC123_IN12 - + {GPIOC_dev, 4, NULL, 0, AFx, ADC1_dev, 14}, // PC4: D63 / A9 - - - ADC12_IN14 - + {GPIOF_dev, 7, TIMER11, 1, 3, ADC3_dev, 5}, // PF7: D64 / A10 - - TIM11_CH1 - ADC3_IN5 - + {GPIOC_dev, 1, NULL, 0, AFx, ADC3_dev, 11}, // PC1: D65 / A11 - - - ADC123_IN11 - // DAC0 - DAC1 (D66 - D67) - {GPIOA_dev, 4, NULL, 0, AFx, ADC2_dev, 4}, // PA4: D66 / A12 - INT - - ADC12_IN4 - DAC_OUT1 - {GPIOA_dev, 5, TIMER8, 5, 3, ADC2_dev, 5}, // PA5: D67 / A13 - INT - TIM2_CH1/TIM8_CH1N - ADC12_IN5 - DAC_OUT2 + {GPIOA_dev, 4, NULL, 0, AFx, ADC2_dev, 4}, // PA4: D66 / A12 - INT - - ADC12_IN4 - DAC_OUT1 + {GPIOA_dev, 5, TIMER8, 5, 3, ADC2_dev, 5}, // PA5: D67 / A13 - INT - TIM2_CH1/TIM8_CH1N - ADC12_IN5 - DAC_OUT2 // CANRX - CANTX (D68 - D69) - {GPIOB_dev, 9, TIMER4, 4, 2, NULL, ADCx}, // PB9: D68 - INT - TIM4_CH4/TIM11_CH1 - - - {GPIOB_dev, 8, TIMER4, 3, 2, NULL, ADCx}, // PB8: D69 - INT - TIM4_CH3/TIM10_CH1 - - + {GPIOB_dev, 9, TIMER4, 4, 2, NULL, ADCx}, // PB9: D68 - INT - TIM4_CH4/TIM11_CH1 - - + {GPIOB_dev, 8, TIMER4, 3, 2, NULL, ADCx}, // PB8: D69 - INT - TIM4_CH3/TIM10_CH1 - - // I2CB - (D70 - D71) - {GPIOB_dev, 7, TIMER4, 2, 2, NULL, ADCx}, // PB7: D70 - - TIM4_CH2 - - I2C1_SDA - {GPIOB_dev, 6, TIMER4, 1, 2, NULL, ADCx}, // PB6: D71 - - TIM4_CH1 - - I2C1_SCL + {GPIOB_dev, 7, TIMER4, 2, 2, NULL, ADCx}, // PB7: D70 - - TIM4_CH2 - - I2C1_SDA + {GPIOB_dev, 6, TIMER4, 1, 2, NULL, ADCx}, // PB6: D71 - - TIM4_CH1 - - I2C1_SCL // SPI - (D72 - D74) - {GPIOB_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PB14: D72 / MISO - - - - SPI2_MISO - {GPIOD_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PD3: D73 / SCK - - - - SPI2_SCK - {GPIOC_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PC3: D74 / MOSI - - - - SPI2_MOSI + {GPIOB_dev, 14, NULL, 0, AFx, NULL, ADCx}, // PB14: D72 / MISO - - - - SPI2_MISO + {GPIOD_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PD3: D73 / SCK - - - - SPI2_SCK + {GPIOC_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PC3: D74 / MOSI - - - - SPI2_MOSI // ESP8266 POWER (D75) - {GPIOH_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PH13: D75 / WIFI_PWR - - - - + {GPIOH_dev, 13, NULL, 0, AFx, NULL, ADCx}, // PH13: D75 / WIFI_PWR - - - - // USB POWER ENABLE (D76) - {GPIOK_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PK4: D76 / USB_PWR - - - - + {GPIOK_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PK4: D76 / USB_PWR - - - - // LCD BACK LIGHT CONTROL (D77) - {GPIOJ_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PJ3: D77 / LCD_BL - - - - + {GPIOJ_dev, 3, NULL, 0, AFx, NULL, ADCx}, // PJ3: D77 / LCD_BL - - - - // AUDIO SELECTION PIN (D78) - {GPIOD_dev, 7, NULL, 0, AFx, NULL, ADCx}, // PD7: D78 / AUDIO_SEL- - - - + {GPIOD_dev, 7, NULL, 0, AFx, NULL, ADCx}, // PD7: D78 / AUDIO_SEL- - - - +// I2C (D79 - D80) + {GPIOH_dev, 4, NULL, 0, AFx, NULL, ADCx}, // PH4: D79 - - - - + {GPIOH_dev, 5, NULL, 0, AFx, NULL, ADCx}, // PH5: D80 - - - - }; extern const uint8 boardPWMPins[BOARD_NR_PWM_PINS] __FLASH__ = { diff --git a/variants/otto/variant.h b/variants/otto/variant.h index 641ffad..cd67063 100644 --- a/variants/otto/variant.h +++ b/variants/otto/variant.h @@ -1,3 +1,46 @@ +/****************************************************************************** + * The MIT License + * + * Copyright (c) 2011 LeafLabs, LLC. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*****************************************************************************/ + + /** + * @file aeroquad32.h + * @author Marti Bolivar + * @brief Private include file for Maple Native in boards.h + * + * See maple.h for more information on these definitions. + */ + + /* + * 2016 May 31 first release for: + * Adruino OTTO serial ports interface definitions + * + * Arduino srl + * + * Francesco Alessi (alfran) - francesco@arduino.org + */ + #ifndef _VARIANT_ARDUINO_STM32_ #define _VARIANT_ARDUINO_STM32_ @@ -9,22 +52,19 @@ #define digitalPinToBitMask(P) ( BIT(PIN_MAP[P].gpio_bit) ) #define portOutputRegister(port) ( &(port->regs->ODR) ) #define portInputRegister(port) ( &(port->regs->IDR) ) - -#define portSetRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BSRR) ) -#define portClearRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BRR) ) - -#define portConfigRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->CRL) ) +#define portSetRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BSRR) ) +#define portClearRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->BRR) ) +#define portConfigRegister(pin) ( &(PIN_MAP[pin].gpio_device->regs->CRL) ) #include "stm32f4xx_hal.h" #define Port2Pin(port, bit) ((port-'A')*16+bit) - #define CYCLES_PER_MICROSECOND 180 #undef STM32_PCLK1 #undef STM32_PCLK2 -#define STM32_PCLK1 (CYCLES_PER_MICROSECOND*1000000/4) -#define STM32_PCLK2 (CYCLES_PER_MICROSECOND*1000000/2) +#define STM32_PCLK1 (CYCLES_PER_MICROSECOND*1000000/4) +#define STM32_PCLK2 (CYCLES_PER_MICROSECOND*1000000/2) #define SYSTICK_RELOAD_VAL (CYCLES_PER_MICROSECOND*1000-1) @@ -33,141 +73,141 @@ // USART1 - NOT USED #define USART1_TX_GPIO_DEV GPIOB_dev #define USART1_TX_GPIO_PIN 6 -#define USART1_TX_AF 7 +#define USART1_TX_AF 7 #define USART1_RX_GPIO_DEV GPIOB_dev #define USART1_RX_GPIO_PIN 7 -#define USART1_RX_AF 7 +#define USART1_RX_AF 7 // USART2 - Serial2 #define USART2_TX_GPIO_DEV GPIOD_dev #define USART2_TX_GPIO_PIN 5 -#define USART2_TX_AF 7 +#define USART2_TX_AF 7 #define USART2_RX_GPIO_DEV GPIOD_dev #define USART2_RX_GPIO_PIN 6 -#define USART2_RX_AF 7 +#define USART2_RX_AF 7 // USART3 - Serial1 / SerialWiFi #define USART3_TX_GPIO_DEV GPIOB_dev #define USART3_TX_GPIO_PIN 10 -#define USART3_TX_AF 7 +#define USART3_TX_AF 7 #define USART3_RX_GPIO_DEV GPIOB_dev #define USART3_RX_GPIO_PIN 11 -#define USART3_RX_AF 7 +#define USART3_RX_AF 7 -// UART4 - Serial0 -#define UART4_TX_GPIO_DEV GPIOA_dev +// UART4 - Serial +#define UART4_TX_GPIO_DEV GPIOA_dev #define UART4_TX_GPIO_PIN 0 -#define UART4_TX_AF 8 +#define UART4_TX_AF 8 #define UART4_RX_GPIO_DEV GPIOA_dev #define UART4_RX_GPIO_PIN 1 -#define UART4_RX_AF 8 +#define UART4_RX_AF 8 // UART5 - NOT USED -#define UART5_TX_GPIO_DEV GPIOD_dev +#define UART5_TX_GPIO_DEV GPIOD_dev #define UART5_TX_GPIO_PIN 2 -#define UART5_TX_AF 8 +#define UART5_TX_AF 8 #define UART5_RX_GPIO_DEV GPIOC_dev #define UART5_RX_GPIO_PIN 12 -#define UART5_RX_AF 8 +#define UART5_RX_AF 8 // USART6 - Serial3 #define USART6_TX_GPIO_DEV GPIOG_dev #define USART6_TX_GPIO_PIN 14 -#define USART6_TX_AF 8 +#define USART6_TX_AF 8 #define USART6_RX_GPIO_DEV GPIOG_dev #define USART6_RX_GPIO_PIN 9 -#define USART6_RX_AF 8 +#define USART6_RX_AF 8 // UART7 - NOT USED -#define UART7_TX_GPIO_DEV GPIOF_dev +#define UART7_TX_GPIO_DEV GPIOF_dev #define UART7_TX_GPIO_PIN 7 -#define UART7_TX_AF 8 +#define UART7_TX_AF 8 #define UART7_RX_GPIO_DEV GPIOF_dev #define UART7_RX_GPIO_PIN 6 -#define UART7_RX_AF 8 +#define UART7_RX_AF 8 // UART8 - NOT USED -#define UART8_TX_GPIO_DEV GPIOE_dev +#define UART8_TX_GPIO_DEV GPIOE_dev #define UART8_TX_GPIO_PIN 0 -#define UART8_TX_AF 8 +#define UART8_TX_AF 8 #define UART8_RX_GPIO_DEV GPIOE_dev #define UART8_RX_GPIO_PIN 1 -#define UART8_RX_AF 8 +#define UART8_RX_AF 8 -#define GPIO_PINS 165 +#define GPIO_PINS 165 #define BOARD_NR_PWM_PINS 26 #define BOARD_NR_ADC_PINS 14 #define BOARD_NR_USED_PINS 80 // Analog PIN Definition -#define A0 D54 -#define A1 D55 -#define A2 D56 -#define A3 D57 -#define A4 D58 -#define A5 D59 -#define A6 D60 -#define A7 D61 -#define A8 D62 -#define A9 D63 -#define A10 D64 -#define A11 D65 -#define A12 D66 -#define A13 D67 +#define A0 D54 +#define A1 D55 +#define A2 D56 +#define A3 D57 +#define A4 D58 +#define A5 D59 +#define A6 D60 +#define A7 D61 +#define A8 D62 +#define A9 D63 +#define A10 D64 +#define A11 D65 +#define A12 D66 +#define A13 D67 // DAC PIN Definition -#define DAC0 D66 -#define DAC1 D67 +#define DAC0 D66 +#define DAC1 D67 // LEDs PIN Definition -#define LED_L D13 -#define LED_BUILTIN D13 +#define LED_L D13 +#define LED_BUILTIN D13 // CAN PIN -#define CANRX D68 -#define CANTX D69 +#define CANRX D68 +#define CANTX D69 // #define CANRX1 D // #define CANTX1 D // SPI PIN -#define MISO D72 -#define SCK D73 -#define MOSI D74 -#define SS D23 -#define MISO1 D12 -#define SCK1 D13 -#define MOSI1 D11 -#define SS1 D10 +#define MISO D72 +#define SCK D73 +#define MOSI D74 +#define SS D23 +#define MISO1 D12 +#define SCK1 D13 +#define MOSI1 D11 +#define SS1 D10 // I2C PIN -#define SCL D70 -#define SDA D71 -#define SDA1 D20 -#define SCL1 D21 +#define SCL D70 +#define SDA D71 +#define SDA1 D20 +#define SCL1 D21 // SERIAL PORT PIN -#define RX D0 -#define TX D1 -#define RX1 D19 -#define TX1 D18 -#define RX2 D17 -#define TX2 D16 -#define RX3 D15 -#define TX3 D14 +#define RX D0 +#define TX D1 +#define RX1 D19 +#define TX1 D18 +#define RX2 D17 +#define TX2 D16 +#define RX3 D15 +#define TX3 D14 // WIFI POWER PIN -#define WIFI_PWR D75 +#define WIFI_PWR D75 // USB POWER PIN -#define USB_PWR D76 +#define USB_PWR D76 // LCD CONTROL -#define LCD_BL D77 +#define LCD_BL D77 // MIC SEL -#define MIC_SEL D78 -#define CODEC 0 -#define MCU 1 +#define MIC_SEL D78 +#define CODEC 0 +#define MCU 1 #endif #endif From f65f711b723793b9e0a5dee76f4e468630cc617d Mon Sep 17 00:00:00 2001 From: alfran Date: Tue, 14 Mar 2017 12:38:09 +0100 Subject: [PATCH 2/2] renamed Serial0 to Serial and removed unwanted files --- cores/arduino/HardwareSerial.cpp | 2 +- cores/arduino/HardwareSerial.h | 2 +- cores/arduino/usb_serial.cpp | 2 +- cores/arduino/usb_serial.h | 2 +- .../SimpleAudioPlayer/SimpleAudioPlayer.ino | 18 +- .../SimpleAudioPlayerWithDebug.ino | 161 ------------------ .../SimpleAudioRecorder.ino | 56 +++--- libraries/SD/examples/CardInfo/CardInfo.ino | 52 +++--- .../SD/examples/Datalogger/Datalogger.ino | 21 +-- libraries/SD/examples/DumpFile/DumpFile.ino | 13 +- libraries/SD/examples/Files/Files.ino | 27 ++- libraries/SD/examples/Full/Full.ino | 160 ++++++++--------- libraries/SD/examples/ReadWrite/ReadWrite.ino | 22 ++- libraries/SD/examples/listfiles/listfiles.ino | 49 +++--- 14 files changed, 204 insertions(+), 383 deletions(-) delete mode 100644 libraries/Audio/example/SimpleAudioPlayerWithDebug/SimpleAudioPlayerWithDebug.ino diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 76fd1f1..2b37d3b 100755 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -44,7 +44,7 @@ /* UART handler declaration */ UART_HandleTypeDef UartHandle; -HardwareSerial Serial0(UART4_dev); +HardwareSerial Serial(UART4_dev);//Serial0(UART4_dev); HardwareSerial Serial1(USART3_dev); HardwareSerial Serial2(USART2_dev); HardwareSerial Serial3(USART6_dev); diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index fd69f54..b2c3ad9 100755 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -79,7 +79,7 @@ class HardwareSerial : public Stream { uint8 rx_pin; }; -extern HardwareSerial Serial0; +extern HardwareSerial Serial;//Serial0; extern HardwareSerial Serial1; extern HardwareSerial Serial2; extern HardwareSerial Serial3; diff --git a/cores/arduino/usb_serial.cpp b/cores/arduino/usb_serial.cpp index e6506f9..9e321bc 100755 --- a/cores/arduino/usb_serial.cpp +++ b/cores/arduino/usb_serial.cpp @@ -57,7 +57,7 @@ extern __IO uint32_t UserRxBufPtrIn; extern __IO uint32_t UserRxBufPtrOut; __IO uint32_t usbEnableBlockingTx; -USBSerial Serial; +//USBSerial Serial; USBSerial SerialUSB; diff --git a/cores/arduino/usb_serial.h b/cores/arduino/usb_serial.h index 630b10e..e9bafe4 100755 --- a/cores/arduino/usb_serial.h +++ b/cores/arduino/usb_serial.h @@ -71,7 +71,7 @@ class USBSerial : public Stream { }; -extern USBSerial Serial; +//extern USBSerial Serial; extern USBSerial SerialUSB; #endif diff --git a/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino b/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino index 2bf7fb1..47a6e48 100644 --- a/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino +++ b/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -22,8 +22,8 @@ void setup() { // initialize serial communication at 9600 bits per second: - Serial.begin(115200); - delay(15000); + SerialUSB.begin(115200); + while(!SerialUSB); /* Test begin() method */ while (SD.begin(SD_DETECT_PIN) != TRUE) @@ -38,21 +38,21 @@ void loop() { const int S = 1024; // Number of samples to read in block uint32_t buffer[S]; int duration; - delay(5000); // delay for console + delay(1000); // delay for console File myFile = SD.open("test.wav"); if (!myFile.available()) { // if the file didn't open, print an error and stop - Serial.println("error opening test.wav"); + SerialUSB.println("error opening test.wav"); while (true); } else { - Serial.println("test.wav open OK"); + SerialUSB.println("test.wav open OK"); } myFile.read((void*) &WaveFormat, sizeof(WaveFormat)); delay(1000); - Serial.println("STARTUP AUDIO\r\n"); + SerialUSB.println("STARTUP AUDIO\r\n"); delay(1000); Audio.begin(WaveFormat.SampleRate, 100); @@ -68,7 +68,7 @@ void loop() { // Every 100 block print a '.' count++; if (count == 1000) { - Serial.print("."); + SerialUSB.print("."); count = 0; } // read from the file into buffer @@ -78,11 +78,11 @@ void loop() { Audio.write(buffer, sizeof(buffer)); } /* reaching end of file */ - Serial.println("End of file. Thank you for listening!"); + SerialUSB.println("End of file. Thank you for listening!"); Audio.end(); myFile.close(); delay(5000); - Serial.println("Restart Playing"); + SerialUSB.println("Restart Playing"); } diff --git a/libraries/Audio/example/SimpleAudioPlayerWithDebug/SimpleAudioPlayerWithDebug.ino b/libraries/Audio/example/SimpleAudioPlayerWithDebug/SimpleAudioPlayerWithDebug.ino deleted file mode 100644 index 4f7d9a6..0000000 --- a/libraries/Audio/example/SimpleAudioPlayerWithDebug/SimpleAudioPlayerWithDebug.ino +++ /dev/null @@ -1,161 +0,0 @@ -/* - Simple Audio Player With Debug - - Demonstrates the use of the Audio library for the Arduino OTTO - - Hardware required : - * SD card in the Arduino OTTO slot - * A sound file named "test.wav" in the root directory of the SD card - * Only 22MHz and 48MHz supported for now - * A speaker to connect to the audio amplifier - - Original by Massimo Banzi September 20, 2012 - Modified by Scott Fitzgerald October 19, 2012 - Modified by Laurent Meunier 2016 - based with STM32 MCD Application examples support - Modified by Francesco Alessi October 25, 2016 - - This example code is in the public domain - -*/ - -#include -#include - -int i2c_status; -int error_status; -int sd_status; -int audio_status; -int cb_error; - -typedef struct { - uint32_t ChunkID; /* 0 */ - uint32_t FileSize; /* 4 */ - uint32_t FileFormat; /* 8 */ - uint32_t SubChunk1ID; /* 12 */ - uint32_t SubChunk1Size; /* 16*/ - uint16_t AudioFormat; /* 20 */ - uint16_t NbrChannels; /* 22 */ - uint32_t SampleRate; /* 24 */ - - uint32_t ByteRate; /* 28 */ - uint16_t BlockAlign; /* 32 */ - uint16_t BitPerSample; /* 34 */ - uint32_t SubChunk2ID; /* 36 */ - uint32_t SubChunk2Size; /* 40 */ -}WAVE_FormatTypeDef; - -void setup() { - i2c_status = 0; - cb_error = 0; - - // initialize serial communication at 9600 bits per second: - Serial.begin(115200); - while(!Serial); - Serial.println("Starting..."); - - - /* Test begin() method */ - while (SD.begin(SD_DETECT_PIN) != TRUE) - { - delay(10); - } -} - -void loop() { - int count = 0; - WAVE_FormatTypeDef WaveFormat; - const int S = 1024; // Number of samples to read in block - uint32_t buffer[S]; - int duration; - //delay(5000); // delay for console - - File myFile = SD.open("test.wav"); - if (!myFile.available()) { - // if the file didn't open, print an error and stop - Serial.println("error opening test.wav"); - while (true); - } else { - Serial.println("test.wav open OK"); - } - - myFile.read((void*) &WaveFormat, sizeof(WaveFormat)); - Serial.print("Sample rate: "); - Serial.print(WaveFormat.SampleRate); - Serial.println(" Hz "); - Serial.print("Byte rate: "); - Serial.print(WaveFormat.ByteRate); - Serial.println(" Hz"); - Serial.print("Bytes per sample: "); - Serial.println(WaveFormat.ByteRate / WaveFormat.SampleRate); - Serial.print("Channels number: "); - Serial.println(WaveFormat.NbrChannels); - duration = WaveFormat.FileSize / WaveFormat.ByteRate; - Serial.print("Duration: "); - Serial.print(duration); - Serial.println(" sec"); - Serial.print("File Size : "); - Serial.print((int)(WaveFormat.FileSize/1024)); - Serial.println(" KB"); - - //delay(1000); - Serial.println("STARTUP AUDIO\r\n"); - //delay(1000); - audio_status = Audio.begin(WaveFormat.SampleRate, 100); - - // delay(1000); - - if(audio_status > 0) { - Serial.println("ERROR in AUDIO INIT"); - } - - Serial.println("Prepare Playing"); - - // Prepare samples - int volume = 100; - Audio.prepare(NULL, S, volume); - - Serial.println("Playing"); - - Serial.println(Audio.getBuffer()); - Serial.println(Audio.getHalf()); - Serial.println(Audio.getLast()); - Serial.println(Audio.getBufferSize()); - - //delay(1000); - - while (myFile.available()) { - // Every 100 block print a '.' - count++; - if (count == 1000) { - Serial.print("."); - count = 0; - } - // read from the file into buffer - myFile.read(buffer, sizeof(buffer)); - - // Feed samples to audio - Audio.write(buffer, sizeof(buffer)); - } - /* reaching end of file */ - Serial.println(""); - Serial.println("End of file. Thank you for listening!"); - Audio.end(); - myFile.close(); - - Serial.println("Printing info"); - - - Serial.print("i2c_status: "); - Serial.println(i2c_status); - Serial.print("error_status: "); - Serial.println(error_status); - Serial.print("playedBytes: "); - Serial.println(Audio.playedBytes()); - Serial.print("receivedBytes: "); - Serial.println(Audio.receivedBytes()); - Serial.print("cb_error: "); - Serial.println(cb_error); - delay(5000);//delay in between reads for stability - Serial.println("Restart Playing"); - -} diff --git a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino index c963dc4..6bef58c 100644 --- a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino +++ b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino @@ -10,7 +10,7 @@ Original by Frederic Pillon November 09, 2016 This example code is in the public domain - + * A sound file named "record.wav" in the root directory of the SD card * will be created. Record duration is 30 seconds. @@ -26,9 +26,9 @@ const char recFile[] = "record.wav"; #define RECORD_5PERCENT ((5*REC_SAMPLE_LENGTH)/100) void setup() { - // initialize serial communication at 115200 bits per second: - Serial.begin(115200); - delay(15000); + // initialize SerialUSB communication at 115200 bits per second: + SerialUSB.begin(115200); + while(!SerialUSB); while (SD.begin(SD_DETECT_PIN) != TRUE) { @@ -48,37 +48,37 @@ void loop() { File myFile = SD.open(recFile, FILE_WRITE); if (!SD.exists(recFile)) { // If the file didn't open, print an error and stop - Serial.print("Error: failed to create "); - Serial.println(recFile); + SerialUSB.print("Error: failed to create "); + SerialUSB.println(recFile); while (true); } else { - Serial.print(recFile); - Serial.println(" created succesfully."); + SerialUSB.print(recFile); + SerialUSB.println(" created succesfully."); } // Initialize header file status = WavProcess_EncInit(&WaveFormat, AUDIO_IN_FREQUENCY, pHeaderBuff); if( status != 0 ) { - Serial.print("Error: could not encode wav header: "); - Serial.println(status, DEC); - while (true); + SerialUSB.print("Error: could not encode wav header: "); + SerialUSB.println(status, DEC); + while (true); } if (myFile.write(pHeaderBuff, sizeof(pHeaderBuff)) != sizeof(pHeaderBuff)){ - Serial.print("Error: could not write header to "); - Serial.println(recFile); + SerialUSB.print("Error: could not write header to "); + SerialUSB.println(recFile); while (true); } delay(1000); - Serial.println("Start AUDIO record"); + SerialUSB.println("Start AUDIO record"); delay(1000); status = Audio.begin(WaveFormat.SampleRate, 100, AUDIO_IN); if (status != 0) { - Serial.print("Error: Audio could not begin: "); - Serial.println(status, DEC); + SerialUSB.print("Error: Audio could not begin: "); + SerialUSB.println(status, DEC); while (true); } else { - Serial.println("Audio begin: OK"); + SerialUSB.println("Audio begin: OK"); } delay(1000); @@ -87,42 +87,42 @@ void loop() { int volume = 100; Audio.prepare(NULL, S, volume); delay(1000); - + // MAX Recording time reached, so stop audio interface and close file while ( Audio.getSampleIn() < REC_SAMPLE_LENGTH) { if ( Audio.isBufferInFull()) { byteswritten = myFile.write((uint8_t*)Audio.getBufferInWithOffset(), Audio.getBufferInSize()); Audio.setBufferInEmpty(byteswritten); } - + // Display percent of recording every 5% if ( ((Audio.getSampleIn() / RECORD_5PERCENT) - count) == 1) - { + { count++; - Serial.print(5*count, DEC); - Serial.println("%"); + SerialUSB.print(5*count, DEC); + SerialUSB.println("%"); } - + } - + // Update wav header file if (myFile.seek(0) == TRUE) { // Update the wav file header and save it into wav file WavProcess_HeaderUpdate(pHeaderBuff, Audio.getSampleIn()); if (myFile.write(pHeaderBuff, sizeof(pHeaderBuff)) != sizeof(pHeaderBuff)){ - Serial.print("Error: header not updated to "); - Serial.println(recFile); + SerialUSB.print("Error: header not updated to "); + SerialUSB.println(recFile); while (true); } } else { - Serial.println("Error: could not update wav header."); + SerialUSB.println("Error: could not update wav header."); while (true); } - Serial.println("End of recording. Thank you!"); + SerialUSB.println("End of recording. Thank you!"); Audio.end(); myFile.close(); while(1); diff --git a/libraries/SD/examples/CardInfo/CardInfo.ino b/libraries/SD/examples/CardInfo/CardInfo.ino index 9adc0d3..f8555a1 100644 --- a/libraries/SD/examples/CardInfo/CardInfo.ino +++ b/libraries/SD/examples/CardInfo/CardInfo.ino @@ -5,7 +5,7 @@ SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not. - * SD card attached + * SD card attached */ // include the SD library: @@ -18,62 +18,62 @@ void setup() { bool disp = false; // Open serial communications and wait for port to open: - Serial.begin(9600); - - while (!Serial); - Serial.print("\nInitializing SD card..."); + SerialUSB.begin(9600); + + while (!SerialUSB); + SerialUSB.print("\nInitializing SD card..."); while(!card.init(SD_DETECT_PIN)) { if (!disp) { - Serial.println("initialization failed. Is a card inserted?"); + SerialUSB.println("initialization failed. Is a card inserted?"); disp = true; } delay(10); } - Serial.println("A card is present."); - + SerialUSB.println("A card is present."); + // print the type of card - Serial.print("\nCard type: "); + SerialUSB.print("\nCard type: "); switch (card.type()) { case STD_CAPACITY_SD_CARD_V1_1: - Serial.println("SD1"); + SerialUSB.println("SD1"); break; case STD_CAPACITY_SD_CARD_V2_0: - Serial.println("SD2"); + SerialUSB.println("SD2"); break; case HIGH_CAPACITY_SD_CARD: - Serial.println("SDHC"); + SerialUSB.println("SDHC"); break; default: - Serial.println("Unknown"); + SerialUSB.println("Unknown"); } - + // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!fatFs.init()) { - Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + SerialUSB.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; } - + // print the type and size of the first FAT-type volume uint32_t volumesize; - Serial.print("\nVolume type is FAT"); - Serial.println(fatFs.fatType(), DEC); - Serial.println(); + SerialUSB.print("\nVolume type is FAT"); + SerialUSB.println(fatFs.fatType(), DEC); + SerialUSB.println(); volumesize = fatFs.blocksPerCluster(); // clusters are collections of blocks volumesize *= fatFs.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes - Serial.print("Volume size (bytes): "); - Serial.println(volumesize); - Serial.print("Volume size (Kbytes): "); + SerialUSB.print("Volume size (bytes): "); + SerialUSB.println(volumesize); + SerialUSB.print("Volume size (Kbytes): "); volumesize /= 1024; - Serial.println(volumesize); - Serial.print("Volume size (Mbytes): "); + SerialUSB.println(volumesize); + SerialUSB.print("Volume size (Mbytes): "); volumesize /= 1024; - Serial.println(volumesize); + SerialUSB.println(volumesize); - Serial.println("\nFiles found on the card (name, date and size in bytes): "); + SerialUSB.println("\nFiles found on the card (name, date and size in bytes): "); File root = SD.openRoot(); // list all files in the card with date and size diff --git a/libraries/SD/examples/Datalogger/Datalogger.ino b/libraries/SD/examples/Datalogger/Datalogger.ino index 3603769..e2459f1 100644 --- a/libraries/SD/examples/Datalogger/Datalogger.ino +++ b/libraries/SD/examples/Datalogger/Datalogger.ino @@ -15,19 +15,19 @@ void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { + SerialUSB.begin(9600); + while (!SerialUSB) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print("Initializing SD card..."); + SerialUSB.print("Initializing SD card..."); // see if the card is present and can be initialized: while (SD.begin(SD_DETECT_PIN) != TRUE) { delay(10); } delay(100); - Serial.println("card initialized."); + SerialUSB.println("card initialized."); } void loop() @@ -54,20 +54,11 @@ void loop() dataFile.println(dataString); dataFile.close(); // print to the serial port too: - Serial.println(dataString); + SerialUSB.println(dataString); } // if the file isn't open, pop up an error: else { - Serial.println("error opening datalog.txt"); + SerialUSB.println("error opening datalog.txt"); } delay(100); } - - - - - - - - - diff --git a/libraries/SD/examples/DumpFile/DumpFile.ino b/libraries/SD/examples/DumpFile/DumpFile.ino index f0f80f2..6f9fa1c 100644 --- a/libraries/SD/examples/DumpFile/DumpFile.ino +++ b/libraries/SD/examples/DumpFile/DumpFile.ino @@ -16,20 +16,20 @@ void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { + SerialUSB.begin(9600); + while (!SerialUSB) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print("Initializing SD card..."); + SerialUSB.print("Initializing SD card..."); // see if the card is present and can be initialized: while (SD.begin(SD_DETECT_PIN) != TRUE) { delay(10); } delay(100); - Serial.println("card initialized."); + SerialUSB.println("card initialized."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. @@ -38,17 +38,16 @@ void setup() // if the file is available, write to it: if (dataFile) { while (dataFile.available()) { - Serial.write(dataFile.read()); + SerialUSB.write(dataFile.read()); } dataFile.close(); } // if the file isn't open, pop up an error: else { - Serial.println("error opening datalog.txt"); + SerialUSB.println("error opening datalog.txt"); } } void loop() { } - diff --git a/libraries/SD/examples/Files/Files.ino b/libraries/SD/examples/Files/Files.ino index 29708d5..0cb50a2 100644 --- a/libraries/SD/examples/Files/Files.ino +++ b/libraries/SD/examples/Files/Files.ino @@ -15,49 +15,49 @@ File myFile; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { + SerialUSB.begin(9600); + while (!SerialUSB) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print("Initializing SD card..."); + SerialUSB.print("Initializing SD card..."); while (SD.begin(SD_DETECT_PIN) != TRUE) { delay(10); } - Serial.println("initialization done."); + SerialUSB.println("initialization done."); if (SD.exists("example.txt")) { - Serial.println("example.txt exists."); + SerialUSB.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + SerialUSB.println("example.txt doesn't exist."); } // open a new file and immediately close it: - Serial.println("Creating example.txt..."); + SerialUSB.println("Creating example.txt..."); myFile = SD.open("example.txt", FILE_WRITE); myFile.close(); // Check to see if the file exists: if (SD.exists("example.txt")) { - Serial.println("example.txt exists."); + SerialUSB.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + SerialUSB.println("example.txt doesn't exist."); } // delete the file: - Serial.println("Removing example.txt..."); + SerialUSB.println("Removing example.txt..."); SD.remove("example.txt"); if (SD.exists("example.txt")) { - Serial.println("example.txt exists."); + SerialUSB.println("example.txt exists."); } else { - Serial.println("example.txt doesn't exist."); + SerialUSB.println("example.txt doesn't exist."); } } @@ -65,6 +65,3 @@ void loop() { // nothing happens after setup finishes. } - - - diff --git a/libraries/SD/examples/Full/Full.ino b/libraries/SD/examples/Full/Full.ino index 488681e..6959cb9 100644 --- a/libraries/SD/examples/Full/Full.ino +++ b/libraries/SD/examples/Full/Full.ino @@ -15,8 +15,8 @@ File MyFile; void setup() { - Serial.begin(9600); - while (!Serial); + SerialUSB.begin(9600); + while (!SerialUSB); /* Test begin() method */ while (SD.begin(SD_DETECT_PIN) != TRUE) @@ -26,168 +26,168 @@ void setup() delay(100); /* Test mkdir() method */ - Serial.println("Creating 'STM32F4' directory"); + SerialUSB.println("Creating 'STM32F4' directory"); SD.mkdir("STM32F4"); - Serial.println("Creating 'ARDUINO' directory"); + SerialUSB.println("Creating 'ARDUINO' directory"); SD.mkdir("ARDUINO"); - Serial.println("Creating 'ARDUINO/OTTO' directory"); + SerialUSB.println("Creating 'ARDUINO/OTTO' directory"); SD.mkdir("ARDUINO/OTTO"); /* Test open() method */ - Serial.println("Opening 'STM32F4/Toremove.txt' file"); + SerialUSB.println("Opening 'STM32F4/Toremove.txt' file"); MyFile = SD.open("STM32F4/Toremove.txt", FILE_WRITE); if(MyFile) { - Serial.println("Closing 'STM32F4/Toremove.txt' file"); + SerialUSB.println("Closing 'STM32F4/Toremove.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'STM32F4/Toremove.txt' file"); + SerialUSB.println("Error to open 'STM32F4/Toremove.txt' file"); } - Serial.println("Opening 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); MyFile = SD.open("ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt", FILE_WRITE); if(MyFile) { /* Test print() method */ - Serial.print("writing \""); - Serial.print((const char*)wtext); - Serial.println("\" into ARDUINO_OTTO_TEXT.txt file"); + SerialUSB.print("writing \""); + SerialUSB.print((const char*)wtext); + SerialUSB.println("\" into ARDUINO_OTTO_TEXT.txt file"); byteswritten = MyFile.print((const char*)wtext); byteswritten += MyFile.print("\n"); - Serial.print(byteswritten, DEC); - Serial.println(" bytes written."); - Serial.println("Closing 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.print(byteswritten, DEC); + SerialUSB.println(" bytes written."); + SerialUSB.println("Closing 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); } - Serial.println("Opening 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); MyFile = SD.open("ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt"); if(MyFile) { bytesread = MyFile.read(rtext, MyFile.size()); - Serial.println("Closing 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.println("Closing 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/ARDUINO_OTTO_TEXT.txt' file"); } - Serial.println("Opening 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/TEXT.txt' file"); MyFile = SD.open("ARDUINO/OTTO/TEXT.txt", FILE_WRITE); if(MyFile) { byteswritten = MyFile.print((const char*)rtext); MyFile.flush(); - Serial.println("Closing 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Closing 'ARDUINO/OTTO/TEXT.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/TEXT.txt' file"); } - Serial.println("Opening 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/TEXT.txt' file"); MyFile = SD.open("ARDUINO/OTTO/TEXT.txt"); if(MyFile) { /* Test size() method */ file_size = MyFile.size(); - Serial.print("TEXT.txt size: "); - Serial.println(file_size); + SerialUSB.print("TEXT.txt size: "); + SerialUSB.println(file_size); /* Test position and seek method */ - Serial.print("TEXT.txt position value: "); - Serial.println(MyFile.position()); + SerialUSB.print("TEXT.txt position value: "); + SerialUSB.println(MyFile.position()); if(!MyFile.seek(MyFile.size()+1)) { - Serial.println("TEXT.txt seek value over size: OK"); + SerialUSB.println("TEXT.txt seek value over size: OK"); } else { - Serial.println("TEXT.txt seek value over size: KO"); + SerialUSB.println("TEXT.txt seek value over size: KO"); } if(MyFile.seek(MyFile.size())) { - Serial.println("TEXT.txt seek value to size: OK"); + SerialUSB.println("TEXT.txt seek value to size: OK"); } else { - Serial.println("TEXT.txt seek value to size: KO"); + SerialUSB.println("TEXT.txt seek value to size: KO"); } - Serial.print("TEXT.txt position value: "); - Serial.println(MyFile.position()); + SerialUSB.print("TEXT.txt position value: "); + SerialUSB.println(MyFile.position()); if(MyFile.seek(0)) { - Serial.println("TEXT.txt seek value to 0: OK"); + SerialUSB.println("TEXT.txt seek value to 0: OK"); } else { - Serial.println("TEXT.txt seek value to 0: KO"); + SerialUSB.println("TEXT.txt seek value to 0: KO"); } - Serial.print("TEXT.txt position value: "); - Serial.println(MyFile.position()); + SerialUSB.print("TEXT.txt position value: "); + SerialUSB.println(MyFile.position()); /* Test peek() method */ - Serial.println("TEXT.txt peek (10 times): "); + SerialUSB.println("TEXT.txt peek (10 times): "); for(i = 0; i<10; i++) { peek_val = MyFile.peek(); - Serial.print(peek_val); - Serial.print(" '"); - Serial.write(peek_val); - Serial.println("'"); + SerialUSB.print(peek_val); + SerialUSB.print(" '"); + SerialUSB.write(peek_val); + SerialUSB.println("'"); } i = 0; /* Test available() and read() methods */ - Serial.println("TEXT.txt content read byte per byte: "); + SerialUSB.println("TEXT.txt content read byte per byte: "); while(MyFile.available()) { rtext[i] = (uint8)MyFile.read(); - Serial.print(rtext[i]); - Serial.print(" '"); - Serial.write(rtext[i]); - Serial.println("'"); + SerialUSB.print(rtext[i]); + SerialUSB.print(" '"); + SerialUSB.write(rtext[i]); + SerialUSB.println("'"); i++; } /* Test close method */ - Serial.println("Closing 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Closing 'ARDUINO/OTTO/TEXT.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/TEXT.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/TEXT.txt' file"); } /* Test isDirectory() method */ MyFile = File("STM32F4"); if(MyFile) { - Serial.print("Is 'STM32F4' is a dir: "); + SerialUSB.print("Is 'STM32F4' is a dir: "); if (MyFile.isDirectory()) - Serial.println("OK"); + SerialUSB.println("OK"); else - Serial.println("KO"); + SerialUSB.println("KO"); } else { - Serial.println("Error to open 'STM32F4' dir"); + SerialUSB.println("Error to open 'STM32F4' dir"); } - Serial.println("Opening 'STM32F4/Toremove.txt' file"); + SerialUSB.println("Opening 'STM32F4/Toremove.txt' file"); MyFile = SD.open("STM32F4/Toremove.txt"); if(MyFile) { - Serial.print("Is 'STM32F4/Toremove.txt' is a file: "); + SerialUSB.print("Is 'STM32F4/Toremove.txt' is a file: "); if (MyFile.isDirectory()) - Serial.println("KO"); + SerialUSB.println("KO"); else - Serial.println("OK"); - Serial.println("Closing 'STM32F4/Toremove.txt' file"); + SerialUSB.println("OK"); + SerialUSB.println("Closing 'STM32F4/Toremove.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'STM32F4/Toremove.txt' file"); + SerialUSB.println("Error to open 'STM32F4/Toremove.txt' file"); } /* Test exists(), remove() and rmdir() methods */ - Serial.print("Removing 'STM32F4/Toremove.txt' file..."); + SerialUSB.print("Removing 'STM32F4/Toremove.txt' file..."); while(SD.exists("STM32F4/Toremove.txt") == TRUE) { SD.remove("STM32F4/Toremove.txt"); } - Serial.println("done"); + SerialUSB.println("done"); - Serial.print("Removing 'STM32F4' dir..."); + SerialUSB.print("Removing 'STM32F4' dir..."); while(SD.exists("STM32F4") == TRUE) { SD.rmdir("STM32F4"); } - Serial.println("done"); + SerialUSB.println("done"); /* Test println(), println(data) methods */ - Serial.println("Opening 'ARDUINO/OTTO/PRINT.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/PRINT.txt' file"); MyFile = SD.open("ARDUINO/OTTO/PRINT.txt", FILE_WRITE); if(MyFile) { String str = String("This is a String object on line 7"); - Serial.print("Printing to 'ARDUINO/OTTO/PRINT.txt' file..."); + SerialUSB.print("Printing to 'ARDUINO/OTTO/PRINT.txt' file..."); MyFile.println("This should be line 1"); MyFile.println(); MyFile.println("This should be line 3"); @@ -195,40 +195,40 @@ void setup() MyFile.println(); MyFile.println("This should be line 6"); MyFile.println(str); - Serial.println("done"); - Serial.println("Closing 'ARDUINO/OTTO/PRINT.txt' file"); + SerialUSB.println("done"); + SerialUSB.println("Closing 'ARDUINO/OTTO/PRINT.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/PRINT.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/PRINT.txt' file"); } /* Test write(buf, len) method */ - Serial.println("Opening 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/WRITE.txt' file"); MyFile = SD.open("ARDUINO/OTTO/WRITE.txt", FILE_WRITE); if(MyFile) { - Serial.print("Writing 'ARDUINO/OTTO/WRITE.txt' file: "); + SerialUSB.print("Writing 'ARDUINO/OTTO/WRITE.txt' file: "); byteswritten = MyFile.write(wtext, BUFFERSIZE); - Serial.print(byteswritten); - Serial.println(" bytes written"); - Serial.println("Closing 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.print(byteswritten); + SerialUSB.println(" bytes written"); + SerialUSB.println("Closing 'ARDUINO/OTTO/WRITE.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/WRITE.txt' file"); } /* Test read(buf, len) method */ - Serial.println("Opening 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.println("Opening 'ARDUINO/OTTO/WRITE.txt' file"); MyFile = SD.open("ARDUINO/OTTO/WRITE.txt"); if(MyFile) { - Serial.println("Reading 'ARDUINO/OTTO/WRITE.txt' file:"); + SerialUSB.println("Reading 'ARDUINO/OTTO/WRITE.txt' file:"); bytesread = MyFile.read(rtext, MyFile.size()); - Serial.println((const char*)rtext); - Serial.println("Closing 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.println((const char*)rtext); + SerialUSB.println("Closing 'ARDUINO/OTTO/WRITE.txt' file"); MyFile.close(); } else { - Serial.println("Error to open 'ARDUINO/OTTO/WRITE.txt' file"); + SerialUSB.println("Error to open 'ARDUINO/OTTO/WRITE.txt' file"); } - Serial.println("###### End of the SD tests ######"); + SerialUSB.println("###### End of the SD tests ######"); } void loop() diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.ino b/libraries/SD/examples/ReadWrite/ReadWrite.ino index 5e8ca6d..3914d02 100644 --- a/libraries/SD/examples/ReadWrite/ReadWrite.ino +++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -16,18 +16,18 @@ File myFile; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { + SerialUSB.begin(9600); + while (!SerialUSB) { ; // wait for serial port to connect. Needed for Leonardo only } - Serial.print("Initializing SD card..."); + SerialUSB.print("Initializing SD card..."); while (SD.begin(SD_DETECT_PIN) != TRUE) { delay(10); } - Serial.println("initialization done."); + SerialUSB.println("initialization done."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. @@ -35,30 +35,30 @@ void setup() // if the file opened okay, write to it: if (myFile) { - Serial.print("Writing to test.txt..."); + SerialUSB.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); // close the file: myFile.close(); - Serial.println("done."); + SerialUSB.println("done."); } else { // if the file didn't open, print an error: - Serial.println("error opening test.txt"); + SerialUSB.println("error opening test.txt"); } // re-open the file for reading: myFile = SD.open("test.txt"); if (myFile) { - Serial.println("test.txt:"); + SerialUSB.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { - Serial.write(myFile.read()); + SerialUSB.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: - Serial.println("error opening test.txt"); + SerialUSB.println("error opening test.txt"); } } @@ -66,5 +66,3 @@ void loop() { // nothing happens after setup } - - diff --git a/libraries/SD/examples/listfiles/listfiles.ino b/libraries/SD/examples/listfiles/listfiles.ino index 90cc7f7..da7d2fd 100644 --- a/libraries/SD/examples/listfiles/listfiles.ino +++ b/libraries/SD/examples/listfiles/listfiles.ino @@ -1,12 +1,12 @@ /* Listfiles - - This example shows how print out the files in a - directory on a SD card - + + This example shows how print out the files in a + directory on a SD card + The circuit: * SD card attached - + This example code is in the public domain. */ @@ -17,30 +17,30 @@ File root; void setup() { // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for Leonardo only + SerialUSB.begin(9600); + while (!SerialUSB) { + ; // wait for Serial port to connect. Needed for Leonardo only } - Serial.print("Initializing SD card..."); + SerialUSB.print("Initializing SD card..."); while (SD.begin(SD_DETECT_PIN) != TRUE) { delay(10); } - Serial.println("initialization done."); + SerialUSB.println("initialization done."); root = SD.open("/"); if(root) printDirectory(root, 0); else - Serial.println("Could not open root"); + SerialUSB.println("Could not open root"); delay(2000); - Serial.println(); - Serial.println("Rewinding, and repeating below:" ); - Serial.println(); + SerialUSB.println(); + SerialUSB.println("Rewinding, and repeating below:" ); + SerialUSB.println(); delay(2000); root.rewindDirectory(); - printDirectory(root, 0); + printDirectory(root, 0); root.close(); } @@ -50,29 +50,26 @@ void loop() } void printDirectory(File dir, int numTabs) { - while(true) { + while(true) { File entry = dir.openNextFile(); if (! entry) { // no more files break; } for (uint8_t i=0; i