Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 8:1db19b529b22, committed 2021-02-21
- Comitter:
- komaida424
- Date:
- Sun Feb 21 05:14:57 2021 +0000
- Parent:
- 7:16bf0085d914
- Commit message:
- rev 020
Changed in this revision
--- a/I2cPeripherals/I2cPeripherals.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/I2cPeripherals/I2cPeripherals.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -1,10 +1,11 @@
#include "mbed.h"
#include "I2cPeripherals.h"
+void wait(float);
//Serial pc(USBTX, USBRX);
I2cPeripherals::I2cPeripherals(PinName sda, PinName scl): _i2c(sda,scl)
{
- _i2c.frequency(200000);
+ _i2c.frequency(400000);
// LCD_contrast = 60;
wait(0.5);
LCD_addr = 0;
@@ -15,7 +16,7 @@
ultrasonic_distance = 0;
//pc.printf("start");
find();
- start();
+ start(50);
}
@@ -108,7 +109,7 @@
tx[0] = 0x3E;
tx[1] = 0x01;
_i2c.write(sens[num].addr,tx,2);
- wait_ms(10);
+ wait(0.001f);
break;
#endif
#ifdef MPU6050
@@ -124,15 +125,15 @@
tx[0] = 0x1A; // DLPF(Digitel low pass filter)
tx[1] = 0x02; // set 0 to 7
_i2c.write(sens[num].addr,tx,2);
- wait(0.01);
+ wait(0.001);
tx[0] = 0x1B;
tx[1] = 0x18; // +-2000deg
_i2c.write(sens[num].addr,tx,2);
- wait(0.01);
+ wait(0.001);
tx[0] = 0x1C;
tx[1] = 0x18; // 00:2g,08:4g,10:8g,18:+-16g
_i2c.write(sens[num].addr,tx,2);
- wait_ms(10);
+ wait(0.001);
break;
#endif
#ifdef L3GD20
@@ -187,7 +188,7 @@
// tx[0]= 0x21; // CTL_REG2
// tx[1]= 0x01; // one shot start
// _i2c.write(sens[num].addr,tx,2);
- wait(1);
+ wait(0.01);
break;
#endif
case 10: //SFR02 ultrasonic
@@ -202,22 +203,23 @@
}
}
-int I2cPeripherals::_putc(int value)
+//int I2cPeripherals::_putc(int value)
+int I2cPeripherals::write_lcd(const char* value)
{
- if ( LCD_addr == 0 ) return value;
+ if ( LCD_addr == 0 ) return -1;
_i2c.start();
_i2c.write(LCD_addr);
_i2c.write(LCD_data);
- _i2c.write(value);
+ _i2c.write(LCD_addr,value,strlen(value));
_i2c.stop();
- return value;
+ return 0;
}
-
+/*
int I2cPeripherals::_getc()
{
return -1;
}
-
+*/
void I2cPeripherals::write_reg(int I2cAddr,char reg_addr,char* data,int len)
{
char tx[17];
@@ -412,7 +414,8 @@
{
char rx[1];
rx[0] = 0;
- while( 1 ) {
+ if ( i2caddr == 0 ) return;
+ while( 1 ) {
_i2c.write(i2caddr,tx,len);
_i2c.write(i2caddr,tx,1,true);
_i2c.read (i2caddr,rx,1);
--- a/I2cPeripherals/I2cPeripherals.h Tue Apr 28 01:48:21 2015 +0000
+++ b/I2cPeripherals/I2cPeripherals.h Sun Feb 21 05:14:57 2021 +0000
@@ -2,6 +2,7 @@
#define MBED_I2cPeripherals_H
#include "mbed.h"
+#include <iostream>
#include "stdarg.h"
#define LPS331AP // baro
@@ -18,12 +19,13 @@
#define ULTRASONIC_ADDR 5
#define I2C_EEPROM_ADDR 0xA0
-class I2cPeripherals : public Stream
+class I2cPeripherals
{
public:
I2cPeripherals(PinName , PinName );
void start(int contrast=60);
+ int write_lcd(const char*);
void write_reg(int,char,char*,int);
void read_reg(int,char,char*,int);
int write_EEPROM(short,char*,int);
@@ -39,8 +41,8 @@
float height_mm();
float height_us();
private:
- virtual int _putc(int value);
- virtual int _getc();
+// virtual int _putc(int value);
+// virtual int _getc();
void i2c_write(int,char*,int);
void find();
int ultrasonic(char);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IAP.lib Sun Feb 21 05:14:57 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/okano/code/IAP/#59f7e32ae397
--- a/IAP/IAP.cpp Tue Apr 28 01:48:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,274 +0,0 @@
-/** IAP : internal Flash memory access library
- *
- * The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual.
- * http://www.nxp.com/documents/user_manual/UM10360.pdf
- * http://www.nxp.com/documents/user_manual/UM10462.pdf
- *
- * LPC1768 --
- * Chapter 2: "LPC17xx Memory map"
- * Chapter 32: "LPC17xx Flash memory interface and programming"
- * refering Rev. 01 - 4 January 2010
- *
- * LPC11U24 --
- * Chapter 2: "LPC11Uxx Memory mapping"
- * Chapter 20: "LPC11Uxx Flash programming firmware"
- * refering Rev. 03 - 16 July 2012
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * revision 1.0 09-Mar-2010 1st release
- * revision 1.1 12-Mar-2010 chaged: to make possible to reserve flash area for user
- * it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
- * revision 2.0 26-Nov-2012 LPC11U24 code added
- * revision 2.1 26-Nov-2012 EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
- * http://mbed.org/users/okini3939/code/M0_EEPROM_test/
- */
-
-#include "mbed.h"
-#include "IAP.h"
-
-#define USER_FLASH_AREA_START_STR( x ) STR( x )
-#define STR( x ) #x
-
-//unsigned char user_area[ USER_FLASH_AREA_SIZE ] __attribute__((section( ".ARM.__at_" USER_FLASH_AREA_START_STR( USER_FLASH_AREA_START ) ), zero_init));
-
-
-/*
- * Reserve of flash area is explained by Igor. Please refer next URL
- * http://mbed.org/users/okano/notebook/iap-in-application-programming-internal-flash-eras/?page=1#comment-271
- */
-
-//unsigned char user_area[ size ] __attribute__((section(".ARM.__at_0x78000"), zero_init));
-
-/*
- * IAP command codes
- * Table 589. "IAP Command Summary", Chapter 8. "IAP commands", usermanual
- */
-
-enum command_code
- {
- IAPCommand_Prepare_sector_for_write_operation = 50,
- IAPCommand_Copy_RAM_to_Flash,
- IAPCommand_Erase_sector,
- IAPCommand_Blank_check_sector,
- IAPCommand_Read_part_ID,
- IAPCommand_Read_Boot_Code_version,
- IAPCommand_Compare,
- IAPCommand_Reinvoke_ISP,
- IAPCommand_Read_device_serial_number,
-#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
- IAPCommand_EEPROM_Write = 61,
- IAPCommand_EEPROM_Read,
-#endif
- };
-
-
-/** Read part identification number
- *
- * @return device ID
- * @see read_serial()
- */
-
-int IAP::read_ID( void ) {
- IAP_command[ 0 ] = IAPCommand_Read_part_ID;
-
- iap_entry( IAP_command, IAP_result );
-
- // return ( (int)IAP_result[ 0 ] );
- return ( (int)IAP_result[ 1 ] ); // to return the number itself (this command always returns CMD_SUCCESS)
-}
-
-
-/** Read device serial number
- *
- * @return device serial number
- * @see read_ID()
- */
-
-int IAP::read_serial( void ) {
- IAP_command[ 0 ] = IAPCommand_Read_device_serial_number;
-
- iap_entry( IAP_command, IAP_result );
-
- // return ( (int)IAP_result[ 0 ] );
- return ( (int)IAP_result[ 1 ] ); // to return the number itself (this command always returns CMD_SUCCESS)
-}
-
-
-/** Blank check sector(s)
- *
- * @param start a Start Sector Number
- * @param end an End Sector Number (should be greater than or equal to start sector number).
- * @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_BLANK | INVALID_SECTOR
- */
-
-int IAP::blank_check( int start, int end ) {
- IAP_command[ 0 ] = IAPCommand_Blank_check_sector;
- IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
- IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number)
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Erase Sector(s)
- *
- * @param start a Start Sector Number
- * @param end an End Sector Number (should be greater than or equal to start sector number).
- * @return error code: CMD_SUCCESS | BUSY | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | INVALID_SECTOR
- */
-
-int IAP::erase( int start, int end ) {
- IAP_command[ 0 ] = IAPCommand_Erase_sector;
- IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
- IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number)
- IAP_command[ 3 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Prepare sector(s) for write operation
- *
- * @param start a Start Sector Number
- * @param end an End Sector Number (should be greater than or equal to start sector number).
- * @return error code: CMD_SUCCESS | BUSY | INVALID_SECTOR
- */
-
-int IAP::prepare( int start, int end ) {
- IAP_command[ 0 ] = IAPCommand_Prepare_sector_for_write_operation;
- IAP_command[ 1 ] = (unsigned int)start; // Start Sector Number
- IAP_command[ 2 ] = (unsigned int)end; // End Sector Number (should be greater than or equal to start sector number).
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Copy RAM to Flash
- *
- * @param source_addr Source RAM address from which data bytes are to be read. This address should be a word boundary.
- * @param target_addr Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
- * @param size Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
- * @return error code: CMD_SUCCESS | SRC_ADDR_ERROR (Address not a word boundary) | DST_ADDR_ERROR (Address not on correct boundary) | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED | COUNT_ERROR (Byte count is not 256 | 512 | 1024 | 4096) | SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION | BUSY
- */
-
-int IAP::write( char *source_addr, char *target_addr, int size ) {
- IAP_command[ 0 ] = IAPCommand_Copy_RAM_to_Flash;
- IAP_command[ 1 ] = (unsigned int)target_addr; // Destination flash address where data bytes are to be written. This address should be a 256 byte boundary.
- IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary.
- IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
- IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-
-/** Compare <address1> <address2> <no of bytes>
- *
- * @param source_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- * @param target_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- * @param size Number of bytes to be compared; should be a multiple of 4.
- * @return error code: CMD_SUCCESS | COMPARE_ERROR | COUNT_ERROR (Byte count is not a multiple of 4) | ADDR_ERROR | ADDR_NOT_MAPPED
- */
-
-int IAP::compare( char *source_addr, char *target_addr, int size ) {
- IAP_command[ 0 ] = IAPCommand_Compare;
- IAP_command[ 1 ] = (unsigned int)target_addr; // Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- IAP_command[ 2 ] = (unsigned int)source_addr; // Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- IAP_command[ 3 ] = size; // Number of bytes to be compared; should be a multiple of 4.
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-/** Compare <address1> <address2> <no of bytes>
- *
- * @param source_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- * @param target_addr Starting flash or RAM address of data bytes to be compared. This address should be a word boundary.
- * @param size Number of bytes to be compared; should be a multiple of 4.
- * @return error code: CMD_SUCCESS | COMPARE_ERROR | COUNT_ERROR (Byte count is not a multiple of 4) | ADDR_ERROR | ADDR_NOT_MAPPED
- */
-
-int IAP::read_BootVer(void) {
- IAP_command[0] = IAPCommand_Read_Boot_Code_version;
- IAP_result[1] = 0; // not sure if in high or low bits.
- iap_entry(IAP_command, IAP_result);
- return ((int)IAP_result[1]);
-}
-
-/** Get user reserved flash start address
- *
- * @return start address of user reserved flash memory
- * @see reserved_flash_area_size()
- */
-
-char * IAP::reserved_flash_area_start( void )
-{
- return ( (char *)USER_FLASH_AREA_START );
-}
-
-
-/** Get user reserved flash size
- *
- * @return size of user reserved flash memory
- * @see reserved_flash_area_start()
- */
-
-int IAP::reserved_flash_area_size( void )
-{
- return ( USER_FLASH_AREA_SIZE );
-}
-
-#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
-/** Copy RAM to EEPROM (LPC11U24)
- *
- * @param source_addr Source RAM address from which data bytes are to be read.
- * @param target_addr Destination EEPROM address where data bytes are to be written.
- * @param size Number of bytes to be written.
- * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
- * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
- */
-int IAP::write_eeprom( char *source_addr, char *target_addr, int size ) {
- IAP_command[ 0 ] = IAPCommand_EEPROM_Write;
- IAP_command[ 1 ] = (unsigned int)target_addr; // Destination EEPROM address where data bytes are to be written. This address should be a 256 byte boundary.
- IAP_command[ 2 ] = (unsigned int)source_addr; // Source RAM address from which data bytes are to be read. This address should be a word boundary.
- IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
- IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-
-/** Copy EEPROM to RAM (LPC11U24)
- *
- * @param source_addr Source EEPROM address from which data bytes are to be read.
- * @param target_addr Destination RAM address where data bytes are to be written.
- * @param size Number of bytes to be written.
- * @return error code: CMD_SUCCESS | SRC_ADDR_NOT_MAPPED | DST_ADDR_NOT_MAPPED
- * Remark: The top 64 bytes of the EEPROM memory are reserved and cannot be written to.
- */
-int IAP::read_eeprom( char *source_addr, char *target_addr, int size ) {
- IAP_command[ 0 ] = IAPCommand_EEPROM_Read;
- IAP_command[ 1 ] = (unsigned int)source_addr; // Source EEPROM address from which data bytes are to be read. This address should be a word boundary.
- IAP_command[ 2 ] = (unsigned int)target_addr; // Destination RAM address where data bytes are to be written. This address should be a 256 byte boundary.
- IAP_command[ 3 ] = size; // Number of bytes to be written. Should be 256 | 512 | 1024 | 4096.
- IAP_command[ 4 ] = cclk_kHz; // CPU Clock Frequency (CCLK) in kHz.
-
- iap_entry( IAP_command, IAP_result );
-
- return ( (int)IAP_result[ 0 ] );
-}
-#endif
-
-
-
--- a/IAP/IAP.h Tue Apr 28 01:48:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,339 +0,0 @@
-/** IAP : internal Flash memory access library
- *
- * The internal Flash memory access is described in the LPC1768 and LPC11U24 usermanual.
- * http://www.nxp.com/documents/user_manual/UM10360.pdf
- * http://www.nxp.com/documents/user_manual/UM10462.pdf
- *
- * LPC1768 --
- * Chapter 2: "LPC17xx Memory map"
- * Chapter 32: "LPC17xx Flash memory interface and programming"
- * refering Rev. 01 - 4 January 2010
- *
- * LPC11U24 --
- * Chapter 2: "LPC11Uxx Memory mapping"
- * Chapter 20: "LPC11Uxx Flash programming firmware"
- * refering Rev. 03 - 16 July 2012
- *
- * Released under the MIT License: http://mbed.org/license/mit
- *
- * revision 1.0 09-Mar-2010 1st release
- * revision 1.1 12-Mar-2010 chaged: to make possible to reserve flash area for user
- * it can be set by USER_FLASH_AREA_START and USER_FLASH_AREA_SIZE in IAP.h
- * revision 2.0 26-Nov.2012 LPC11U24 code added
- * revision 2.1 26-Nov-2012 EEPROM access code imported from Suga koubou san's (http://mbed.org/users/okini3939/) library
- * http://mbed.org/users/okini3939/code/M0_EEPROM_test/
- */
-
-#ifndef MBED_IAP
-#define MBED_IAP
-
-#include "mbed.h"
-
-#if defined(TARGET_LPC1768)// || defined(TARGET_NUCLEO_F401RE)
-
-#define USER_FLASH_AREA_START FLASH_SECTOR_29
-//#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1)
-#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1)
-
-/*
- * memory map information is available in next URL also.
- * http://mbed.org/projects/libraries/svn/mbed/trunk/LPC1768/LPC17xx.h
- */
-
-/** Table for start adress of sectors
- *
- * LPC1768 internal flash memory sector numbers and addresses
- *
- * LPC1768 flash memory are and sector number/size
- * Table 568 "Sectors in a LPC17xx device", Section 5. "Sector numbers", usermanual
- *
- * 0x00000000 - 0x0007FFFF flash (29 sectors)
- *
- * Sector0: 0x00000000 - 0x00000FFF 4K
- * Sector1: 0x00001000 - 0x00001FFF 4K
- * Sector2: 0x00002000 - 0x00002FFF 4K
- * Sector3: 0x00003000 - 0x00003FFF 4K
- * Sector4: 0x00004000 - 0x00004FFF 4K
- * Sector5: 0x00005000 - 0x00005FFF 4K
- * Sector6: 0x00006000 - 0x00006FFF 4K
- * Sector7: 0x00007000 - 0x00007FFF 4K
- * Sector8: 0x00008000 - 0x00008FFF 4K
- * Sector9: 0x00009000 - 0x00009FFF 4K
- * Sector10: 0x0000A000 - 0x0000AFFF 4K
- * Sector11: 0x0000B000 - 0x0000BFFF 4K
- * Sector12: 0x0000C000 - 0x0000CFFF 4K
- * Sector13: 0x0000D000 - 0x0000DFFF 4K
- * Sector14: 0x0000E000 - 0x0000EFFF 4K
- * Sector15: 0x0000F000 - 0x0000FFFF 4K
- *
- * Sector16: 0x00010000 - 0x00017FFF 32K
- * Sector17: 0x00018000 - 0x0001FFFF 32K
- * Sector18: 0x00020000 - 0x00027FFF 32K
- * Sector19: 0x00028000 - 0x0002FFFF 32K
- * Sector20: 0x00030000 - 0x00037FFF 32K
- * Sector21: 0x00038000 - 0x0003FFFF 32K
- * Sector22: 0x00040000 - 0x00047FFF 32K
- * Sector23: 0x00048000 - 0x0004FFFF 32K
- * Sector24: 0x00050000 - 0x00057FFF 32K
- * Sector25: 0x00058000 - 0x0005FFFF 32K
- * Sector26: 0x00060000 - 0x00067FFF 32K
- * Sector27: 0x00068000 - 0x0006FFFF 32K
- * Sector28: 0x00070000 - 0x00077FFF 32K
- * Sector29: 0x00078000 - 0x0007FFFF 32K
- */
-
-#define FLASH_SECTOR_0 0x00000000
-#define FLASH_SECTOR_1 0x00001000
-#define FLASH_SECTOR_2 0x00002000
-#define FLASH_SECTOR_3 0x00003000
-#define FLASH_SECTOR_4 0x00004000
-#define FLASH_SECTOR_5 0x00005000
-#define FLASH_SECTOR_6 0x00006000
-#define FLASH_SECTOR_7 0x00007000
-#define FLASH_SECTOR_8 0x00008000
-#define FLASH_SECTOR_9 0x00009000
-#define FLASH_SECTOR_10 0x0000A000
-#define FLASH_SECTOR_11 0x0000B000
-#define FLASH_SECTOR_12 0x0000C000
-#define FLASH_SECTOR_13 0x0000D000
-#define FLASH_SECTOR_14 0x0000E000
-#define FLASH_SECTOR_15 0x0000F000
-#define FLASH_SECTOR_16 0x00010000
-#define FLASH_SECTOR_17 0x00018000
-#define FLASH_SECTOR_18 0x00020000
-#define FLASH_SECTOR_19 0x00028000
-#define FLASH_SECTOR_20 0x00030000
-#define FLASH_SECTOR_21 0x00038000
-#define FLASH_SECTOR_22 0x00040000
-#define FLASH_SECTOR_23 0x00048000
-#define FLASH_SECTOR_24 0x00050000
-#define FLASH_SECTOR_25 0x00058000
-#define FLASH_SECTOR_26 0x00060000
-#define FLASH_SECTOR_27 0x00068000
-#define FLASH_SECTOR_28 0x00070000
-#define FLASH_SECTOR_29 0x00078000
-#define FLASH_SECTOR_SIZE_0_TO_15 ( 4 * 1024)
-#define FLASH_SECTOR_SIZE_16_TO_29 (32 * 1024)
-
-static char * sector_start_adress[] = {
- (char *)FLASH_SECTOR_0,
- (char *)FLASH_SECTOR_1,
- (char *)FLASH_SECTOR_2,
- (char *)FLASH_SECTOR_3,
- (char *)FLASH_SECTOR_4,
- (char *)FLASH_SECTOR_5,
- (char *)FLASH_SECTOR_6,
- (char *)FLASH_SECTOR_7,
- (char *)FLASH_SECTOR_8,
- (char *)FLASH_SECTOR_9,
- (char *)FLASH_SECTOR_10,
- (char *)FLASH_SECTOR_11,
- (char *)FLASH_SECTOR_12,
- (char *)FLASH_SECTOR_13,
- (char *)FLASH_SECTOR_14,
- (char *)FLASH_SECTOR_15,
- (char *)FLASH_SECTOR_16,
- (char *)FLASH_SECTOR_17,
- (char *)FLASH_SECTOR_18,
- (char *)FLASH_SECTOR_19,
- (char *)FLASH_SECTOR_20,
- (char *)FLASH_SECTOR_21,
- (char *)FLASH_SECTOR_22,
- (char *)FLASH_SECTOR_23,
- (char *)FLASH_SECTOR_24,
- (char *)FLASH_SECTOR_25,
- (char *)FLASH_SECTOR_26,
- (char *)FLASH_SECTOR_27,
- (char *)FLASH_SECTOR_28,
- (char *)FLASH_SECTOR_29
-};
-
-#elif defined(TARGET_NUCLEO_F401RE) //dummy
-
-#define FLASH_SECTOR_29 0x00078000
-#define FLASH_SECTOR_SIZE_0_TO_15 ( 4 * 1024)
-#define FLASH_SECTOR_SIZE_16_TO_29 (32 * 1024)
-#define USER_FLASH_AREA_START FLASH_SECTOR_29
-//#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1)
-#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE_16_TO_29 * 1)
-
-
-#elif defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
-
-#define USER_FLASH_AREA_START FLASH_SECTOR_15
-#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1)
-
-#define FLASH_SECTOR_0 0x00000000
-#define FLASH_SECTOR_1 0x00001000
-#define FLASH_SECTOR_2 0x00002000
-#define FLASH_SECTOR_3 0x00003000
-#define FLASH_SECTOR_4 0x00004000
-#define FLASH_SECTOR_5 0x00005000
-#define FLASH_SECTOR_6 0x00006000
-#define FLASH_SECTOR_7 0x00007000
-#define FLASH_SECTOR_8 0x00008000
-#define FLASH_SECTOR_9 0x00009000
-#define FLASH_SECTOR_10 0x0000A000
-#define FLASH_SECTOR_11 0x0000B000
-#define FLASH_SECTOR_12 0x0000C000
-#define FLASH_SECTOR_13 0x0000D000
-#define FLASH_SECTOR_14 0x0000E000
-#define FLASH_SECTOR_15 0x0000F000
-#define FLASH_SECTOR_SIZE (4 * 1024)
-
-static char * sector_start_adress[] = {
- (char *)FLASH_SECTOR_0,
- (char *)FLASH_SECTOR_1,
- (char *)FLASH_SECTOR_2,
- (char *)FLASH_SECTOR_3,
- (char *)FLASH_SECTOR_4,
- (char *)FLASH_SECTOR_5,
- (char *)FLASH_SECTOR_6,
- (char *)FLASH_SECTOR_7,
- (char *)FLASH_SECTOR_8,
- (char *)FLASH_SECTOR_9,
- (char *)FLASH_SECTOR_10,
- (char *)FLASH_SECTOR_11,
- (char *)FLASH_SECTOR_12,
- (char *)FLASH_SECTOR_13,
- (char *)FLASH_SECTOR_14,
- (char *)FLASH_SECTOR_15
-};
-
-#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1114)
-
-#define USER_FLASH_AREA_START FLASH_SECTOR_7
-#define USER_FLASH_AREA_SIZE (FLASH_SECTOR_SIZE * 1)
-
-/** Table for start adress of sectors
- *
- * LPC11U24 internal flash memory sector numbers and addresses
- *
- * LPC11U24 flash memory are and sector number/size
- * Table 334 "LPC11U1x/2x flash sectors", Section 20. "Sector numbers", usermanual
- *
- * 0x00000000 - 0x00007FFF flash (8 sectors)
- *
- * Sector0: 0x00000000 - 0x00000FFF 4K
- * Sector1: 0x00001000 - 0x00001FFF 4K
- * Sector2: 0x00002000 - 0x00002FFF 4K
- * Sector3: 0x00003000 - 0x00003FFF 4K
- * Sector4: 0x00004000 - 0x00004FFF 4K
- * Sector5: 0x00005000 - 0x00005FFF 4K
- * Sector6: 0x00006000 - 0x00006FFF 4K
- * Sector7: 0x00007000 - 0x00007FFF 4K
- */
-
-#define FLASH_SECTOR_0 0x00000000
-#define FLASH_SECTOR_1 0x00001000
-#define FLASH_SECTOR_2 0x00002000
-#define FLASH_SECTOR_3 0x00003000
-#define FLASH_SECTOR_4 0x00004000
-#define FLASH_SECTOR_5 0x00005000
-#define FLASH_SECTOR_6 0x00006000
-#define FLASH_SECTOR_7 0x00007000
-#define FLASH_SECTOR_SIZE (4 * 1024)
-
-static char * sector_start_adress[] = {
- (char *)FLASH_SECTOR_0,
- (char *)FLASH_SECTOR_1,
- (char *)FLASH_SECTOR_2,
- (char *)FLASH_SECTOR_3,
- (char *)FLASH_SECTOR_4,
- (char *)FLASH_SECTOR_5,
- (char *)FLASH_SECTOR_6,
- (char *)FLASH_SECTOR_7,
-};
-
-#endif
-
-
-/** Error code by IAP routine
- *
- * Table 588 "ISP Return Codes Summary", Section 7.15 "ISP Return Codes", usermanual
- */
-
-enum error_code
- {
- CMD_SUCCESS,
- INVALID_COMMAND,
- SRC_ADDR_ERROR,
- DST_ADDR_ERROR,
- SRC_ADDR_NOT_MAPPED,
- DST_ADDR_NOT_MAPPED,
- COUNT_ERROR,
- INVALID_SECTOR,
- SECTOR_NOT_BLANK,
- SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION,
- COMPARE_ERROR,
- BUSY,
- PARAM_ERROR,
- ADDR_ERROR,
- ADDR_NOT_MAPPED,
- CMD_LOCKED,
- INVALID_CODE,
- INVALID_BAUD_RATE,
- INVALID_STOP_BIT,
- CODE_READ_PROTECTION_ENABLED
- };
-
-
-
-/*
- * IAP routine entry
- *
- * "IAP commands"
- */
-
-#define IAP_LOCATION 0x1fff1ff1
-typedef void (*IAP_call)(unsigned int [], unsigned int []);
-
-/** IAP class
- *
- * Interface for internal flash memory access
- */
-
-
-class IAP {
-public:
-
- /*
- * SystemCoreClock ??? :
- * http://mbed.org/forum/mbed/topic/229/
- * http://mbed.org/users/simon/programs/SystemCoreClock/16mhsh/
- */
-
-
- /** Constructor for IAP
- *
- */
-
- IAP() : iap_entry( reinterpret_cast<IAP_call>(IAP_LOCATION) ), cclk_kHz( SystemCoreClock / 1000 ) {}
- int read_ID( void );
- int read_serial( void );
- int blank_check( int start, int end );
- int erase( int start, int end );
- int prepare( int start, int end );
- int write( char *source_addr, char *target_addr, int size );
- int compare( char *source_addr, char *target_addr, int size );
- int read_BootVer( void );
-
- char *reserved_flash_area_start( void );
- int reserved_flash_area_size( void );
-
-#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
- int write_eeprom( char *source_addr, char *target_addr, int size );
- int read_eeprom( char *source_addr, char *target_addr, int size );
-#endif
-
-private:
- IAP_call iap_entry;
- unsigned int IAP_command[ 5 ];
- unsigned int IAP_result[ 5 ];
- int cclk_kHz;
-
- //int cpu_clock( void );
-}
-;
-
-#endif // #ifndef MBED_IAP
--- a/Limiter/Limiter.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/Limiter/Limiter.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -1,37 +1,22 @@
#include "mbed.h"
#include "Limiter.h"
-Limiter::Limiter(float LIMIT)
+Limiter::Limiter(float RATE)
{
- _limit = LIMIT;
- _rate = 0.05;
- _last= 0;
- skip = false;
-}
-
-void Limiter::differential(float DIFF)
-{
- _limit = DIFF;
+ _rate = RATE;
+ _lastval = 0.0;
}
-void Limiter::rate(float RATE)
+void Limiter::setup(float _cutoffreq,float _interval)
{
- _rate = RATE;
+ _period = 1 / _cutoffreq;
+ _rate = _period / ( _period + _interval );
+ _lastval = 0.0;
}
-float Limiter::calc(float now)
+float Limiter::calc(float _now)
{
- if ( !skip ) {
- skip = true;
- return _last = now;
- }
- float differential = ( now - _last );
-// if ( differential < _limit && differential > -_limit ) _last = now;
- if ( differential > _limit ) _last += _limit * _rate;
- else {
- if ( differential < -_limit ) _last -= _limit * _rate;
- else _last = now;
- }
- return _last;
+ _lastval = _rate * _lastval + ( 1 - _rate ) * _now;
+ return _lastval;
}
;
--- a/Limiter/Limiter.h Tue Apr 28 01:48:21 2015 +0000
+++ b/Limiter/Limiter.h Sun Feb 21 05:14:57 2021 +0000
@@ -7,14 +7,12 @@
class Limiter
{
public:
- Limiter(float limit);
- void differential(float);
- void rate(float);
+ Limiter(float);
+ void setup(float,float);
float calc(float);
private:
- float _last;
- float _limit;
+ float _period;
float _rate;
- bool skip;
+ float _lastval;
};
#endif
\ No newline at end of file
--- a/PulseOut/PulseOut.cpp Tue Apr 28 01:48:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-#include "mbed.h"
-#include "InterruptIn.h"
-#include "PulseOut.h"
-
-PulseOut::PulseOut(PinName _outpin,bool _positive) : pulse(_outpin) //constructa
-{
- if ( _positive )
- pulse = 0;
- else
- pulse = 1;
- positive = _positive;
- width = 0;
-}
-
-void PulseOut::pulsewidth_us(int _width)
-{
- width = _width;
-}
-
-void PulseOut::start()
-{
- if ( width == 0 ) return;
- _timeout.attach_us(this,&PulseOut::stop,width);
- if ( positive )
- pulse = 1;
- else
- pulse = 0;
-}
-
-void PulseOut::period_us(int period)
-{
- //dummy
-}
-
-void PulseOut::stop()
-{
- if ( positive )
- pulse = 0;
- else
- pulse = 1;
- _timeout.detach();
-}
-;
-
-
--- a/PulseOut/PulseOut.h Tue Apr 28 01:48:21 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#ifndef PULSEOUT_H
-#define PULSEOUT_H
-#define POSITIVE true
-#define NEGATIVE false
-
-#include "mbed.h"
-
-class PulseOut
-{
-private:
- Timeout _timeout;
- void stop();
- DigitalOut pulse;
- bool positive;
- int width;
-
-public:
- PulseOut(PinName,bool mode=true);
- void pulsewidth_us(int);
- void period_us(int);
- void start();
-};
-#endif
\ No newline at end of file
--- a/PulseWidthCounter/PulseWidthCounter.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/PulseWidthCounter/PulseWidthCounter.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -2,15 +2,15 @@
#include "InterruptIn.h"
#include "PulseWidthCounter.h"
-PulseWidthCounter::PulseWidthCounter(PinName _interrupt,bool positive) : interrupt(_interrupt) //constructa
+PulseWidthCounter::PulseWidthCounter(PinName inpin,bool positive) : pulsein(inpin) //constructa
{
if ( positive )
- { interrupt.rise(this,&PulseWidthCounter::start);
- interrupt.fall(this,&PulseWidthCounter::stop);
+ { pulsein.rise(callback(this,&PulseWidthCounter::start));
+ pulsein.fall(callback(this,&PulseWidthCounter::stop));
}
else
- { interrupt.fall(this,&PulseWidthCounter::start);
- interrupt.rise(this,&PulseWidthCounter::stop);
+ { pulsein.fall(callback(this,&PulseWidthCounter::start));
+ pulsein.rise(callback(this,&PulseWidthCounter::stop));
}
}
--- a/PulseWidthCounter/PulseWidthCounter.h Tue Apr 28 01:48:21 2015 +0000
+++ b/PulseWidthCounter/PulseWidthCounter.h Sun Feb 21 05:14:57 2021 +0000
@@ -11,12 +11,12 @@
Timer _time;
void start();
void stop();
- InterruptIn interrupt;
+ InterruptIn pulsein;
public:
// Timer time;
PulseWidthCounter(PinName,bool positive=true);
-
+ PulseWidthCounter(const PulseWidthCounter& pwc);
int count;
};
#endif
\ No newline at end of file
--- a/SerialLcd/SerialLcd.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/SerialLcd/SerialLcd.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -1,13 +1,20 @@
#include "mbed.h"
#include "SerialLcd.h"
+void wait(float);
SerialLcd::SerialLcd(PinName TX,PinName RX): _lcd(TX,RX)
{
// LCD_contrast = 60;
}
+int SerialLcd::write(const char* value) {
+ size_t len = strlen(value);
+ return _lcd.write(value,len);
+}
+
int SerialLcd::_putc(int value) {
- _lcd.putc(value);
+ const uint8_t buf = value;
+ _lcd.write(&buf,1);
return value;
}
@@ -17,15 +24,19 @@
void SerialLcd::cls()
{
- _lcd.putc(0xFE);
- _lcd.putc(0x01);
+ char buf[2];
+ buf[0] = 0xFE;
+ buf[1] = 0x01;
+ _lcd.write(buf,2);
wait(0.01);
}
void SerialLcd::locate(int clm,int row)
{
- _lcd.putc(0xFE);
- _lcd.putc( 0x80 + (row * 0x40) + clm );
+ char buf[2];
+ buf[0] = 0xFE;
+ buf[1] = 0x80 + (row * 0x40) + clm ;
+ _lcd.write(buf,2);
wait(0.01);
}
;
--- a/SerialLcd/SerialLcd.h Tue Apr 28 01:48:21 2015 +0000
+++ b/SerialLcd/SerialLcd.h Sun Feb 21 05:14:57 2021 +0000
@@ -2,7 +2,8 @@
#define MBED_SERIALLCD_H
#include "mbed.h"
-#include "stdarg.h"
+#include <Stream.h>
+//#include "stdarg.h"
class SerialLcd : public Stream
{
@@ -11,10 +12,11 @@
void cls();
void locate(int,int);
+ int write(const char*);
private:
virtual int _putc(int value);
virtual int _getc();
- Serial _lcd;
+ BufferedSerial _lcd;
int LCD_addr;
char LCD_cmd;
char LCD_data;
--- a/SoftPWM/SoftPWM.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/SoftPWM/SoftPWM.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -1,6 +1,7 @@
#include "mbed.h"
#include "InterruptIn.h"
#include "SoftPWM.h"
+void wait(float);
SoftPWM::SoftPWM(PinName _outpin,bool _positive) : pulse(_outpin) //constructa
{
@@ -30,7 +31,8 @@
void SoftPWM::start()
{
- _ticker.attach(this,&SoftPWM::TickerInterrapt,interval);
+ uint32_t itv = interval;
+ _ticker.attach(callback(this,&SoftPWM::TickerInterrapt),itv);
}
void SoftPWM::stop()
@@ -80,7 +82,7 @@
void SoftPWM::TickerInterrapt()
{
if ( width <= 0 ) return;
- _timeout.attach(this,&SoftPWM::end,width);
+ _timeout.attach(callback(this,&SoftPWM::end),width);
if ( positive )
pulse = 1;
else
--- a/config.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/config.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -27,7 +27,7 @@
CONFRESET,
FINAL };
-void FlashLED(int);
+void FlashLED(int,float tm=0.1);
char Check_Stick_Dir(char);
void Param_Set_Prompt1(char *,int *,int,int,int,int,char);
void Param_Set_Prompt1(char *,float *,int,float,float,float,char);
@@ -45,6 +45,7 @@
void LCD_printf(char *);
void LCD_cls();
void LCD_locate(int,int);
+void wait(float);
Timer elaps;
@@ -444,7 +445,7 @@
case PARMSET*10: //パラメーター設定
LCD_printf("Parameter Set");
Set_Arrow(1);
- hmax = 9;
+ hmax = 8;
break;
case PARMSET*10+1:
Param_Set_Prompt1("LCD>Contrast",&conf.LCD_Contrast,2,0,63,1,sw);
@@ -480,33 +481,9 @@
Param_Set_Prompt1("Flight Timer",&conf.Flight_Time,2,0,600,10,sw);
break;
case PARMSET*10+8:
- Param_Set_Prompt1("Thro Limit val",&conf.Thro_Limit_Val,2,0,200,1,sw);
- throLimit.differential(conf.Thro_Limit_Val);
- break;
- case PARMSET*10+9:
- Param_Set_Prompt1("Thro Limit Rate",&conf.Thro_Limit_Rate,3,0,1,0.01,sw);
- throLimit.rate(conf.Thro_Limit_Rate);
- break;
-/* case PARMSET*10+7:
- LCD_locate(0,0);
- LCD_printf("Model Type");
- LCD_locate(0,1);
- switch ( sw ) {
- case 'D':
- if ( conf.Model_Type > 0 ) conf.Model_Type -= 1;
- else conf.Model_Type = 3;
- break;
- case 'U':
- if ( conf.Model_Type < 4 ) conf.Model_Type += 1;
- else conf.Model_Type = 0;
- }
- LCD_printf( (char*)ModelName[conf.Model_Type] );
- Set_Arrow(2);
- break;
- case PARMSET*10+8:
Param_Set_Prompt1("Active Gyro Gain",&conf.Active_Gyro_Gain,3,0.0f,1.0f,0.01f,sw);
break;
-*/
+
//設定データの保存
case CONFSTORE*10: //E2PROM Store
LCD_printf("Config Save");
--- a/config.h Tue Apr 28 01:48:21 2015 +0000
+++ b/config.h Sun Feb 21 05:14:57 2021 +0000
@@ -3,7 +3,7 @@
//#define SERIAL_LCD
//#define SOFT_PWM
-#define LPCXpresso
+//#define LPCXpresso
//#define LocalFileOut
#define TX_TYPE 0 // 0:FM 1:IR
@@ -78,7 +78,7 @@
float Thro_Limit_Rate;
public:
config() {
- Revision = 3.11;
+ Revision = 1.01;
Struct_Size = sizeof(config);
Stick_Ref[0] = 1500;
Stick_Ref[1] = 1500;
@@ -115,7 +115,7 @@
Gyro_Gain_Setting = -1;
Cutoff_Freq=0.15;
Flight_Time=360;
- LCD_Contrast = 60;
+ LCD_Contrast = 33;
PWM_Mode = 1;
Throttl_Trim = 0;
PWM_Interval = 3000;
--- a/main.cpp Tue Apr 28 01:48:21 2015 +0000
+++ b/main.cpp Sun Feb 21 05:14:57 2021 +0000
@@ -21,15 +21,18 @@
#include "PulseWidthCounter.h"
#include "string"
#include "SerialLcd.h"
+
+//#if defined(TARGET_NUCLEO_FXXXXX)
+// #include "eeprom_flash.h"
+//#endif
//#include "PID.h"
-#include "SoftPWM.h"
-#include "PulseOut.h"
+//#include "SoftPWM.h"
#include "Limiter.h"
-#ifndef TARGET_NUCLEO_F401RE
- #include "IAP.h"
-#endif
+#include "IAP.h"
+#define DEBUG
//Serial pc(USBTX, USBRX);
+//Serial pc(PA_9,PA_10);
#if defined(TARGET_LPC1768)
DigitalInOut pwmpin[] = { p21,p22,p23,p24 };
@@ -39,59 +42,106 @@
DigitalOut led1(LED1);
// DigitalOut led2(LED2);
InterruptIn ch1(p5);
- PulseWidthCounter ch[6] = { p6,p7,p8,p9,p10,p11 };
+ PulseWidthCounter ch[6] = { PulseWidthCounter(p6),
+ PulseWidthCounter(p7),
+ PulseWidthCounter(p8),
+ PulseWidthCounter(p9),
+ PulseWidthCounter(p10),
+ PulseWidthCounter(p11) };
PwmOut pwm[6] = { p21,p22,p23,p24,p25,p26 };
-// SoftPWM pwm[6] = { p21,p22,p23,p24,p25,p26 };
- SoftPWM buzz(p20);
+// SoftPWM buzz(p20);
I2cPeripherals i2c(p28,p27); //sda scl
SerialLcd lcd(p13,p14);
+ #define PwmNum 6
#define MEM_SIZE 256
#define TARGET_SECTOR 29 // use sector 29 as target sector if it is on LPC1768
IAP iap;
-#elif defined(TARGET_NUCLEO_F401RE)
- DigitalOut led1(LED1);
+#elif defined(TARGET_STM32F1)
+//#define NAZE32BORD
+ #ifdef NAZE32BORD
+ DigitalOut led1(PC_13);
+ InterruptIn ch1(PA_0);
+ PulseWidthCounter ch[6] = { PA_8,PA_11,PB_6,PB_7,PB_8,PB_9};
+ PwmOut pwm[6] = { PA_0,PA_1,PA_2,PA_3,PA_6,PA_7 };
+// SoftPWM buzz(PA_2);
+// I2cPeripherals i2c(I2C_SDA,I2C_SCL); //sda scl
+ I2cPeripherals i2c(PB_9,PB_8); //sda scl
+ SerialLcd lcd(PA_2);
+ #define PwmNum 6
+ #define MEM_SIZE 256
+ #define STM32_EEPROM //24AAXX/24LCXX/24FCXX EEPROM
+ #else
+ DigitalOut led1(PC_13);
+ InterruptIn ch1(PA_0);
+ PulseWidthCounter ch[6] = { PA_11,PA_12,PA_15,PB_3,PB_4,PB_5};
+ PwmOut pwm[6] = { PA_6,PA_7,PB_0,PB_1,PB_10,PB_11 };
+// SoftPWM buzz(PA_2);
+// I2cPeripherals i2c(I2C_SDA,I2C_SCL); //sda scl
+ I2cPeripherals i2c(PB_9,PB_8); //sda scl
+ SerialLcd lcd(PA_2);
+ #define PwmNum 6
+ #define MEM_SIZE 256
+ #define STM32_EEPROM //24AAXX/24LCXX/24FCXX EEPROM
+ #endif
+#elif defined(TARGET_STM32F3)
+ DigitalOut led1(PB_3);
+ InterruptIn ch1(PA_0);
+ PulseWidthCounter ch[6] = { PA_0,PA_1,PB_11,PB_10,PB_4,PB_5};
+ PwmOut pwm[6] = { PA_6,PA_7,PA_11,PA_12,PB_8,PB_9 };
+// SoftPWM buzz(PA_2);
+// I2cPeripherals i2c(I2C_SDA,I2C_SCL); //sda scl
+ I2cPeripherals i2c(PB_7,PB_6); //sda scl
+ SerialLcd lcd(PA_9);
+ #define PwmNum 6
+ #define MEM_SIZE 256
+ #define STM32_EEPROM //24AAXX/24LCXX/24FCXX EEPROM
+#elif defined(TARGET_NUCLEO_F4)
+ DigitalOut led1(PA_5);
InterruptIn ch1(PC_2);
// PulseWidthCounter ch[6] = { PA_0,PA_1,PA_4,PB_0,PC_1,PC_0 };
PulseWidthCounter ch[6] = { A0,A1,A2,A3,A4,A5 };
- PwmOut pwm[6] = { D8,D9,D10,D11,D12,D14 };
-// PwmOut pwm[6] = { D2,D3,D4,D5,D6,D7 };
-// SoftPWM pwm[6] = { PB_3,PB_4,PB_10,PC_6,PB_6,PA_7 };
- SoftPWM buzz(PB_13);
+ PwmOut pwm[6] = { D3,D5,D6,D9,D11,D12 };
+// SoftPWM buzz(PB_13);
// I2cPeripherals i2c(I2C_SDA,I2C_SCL); //sda scl
- I2cPeripherals i2c(D5,D7); //sda scl
- SerialLcd lcd(PA_11,PA_12);
+ I2cPeripherals i2c(PB_9,PB_8); //sda scl
+ SerialLcd lcd(PA_11);
+ #define PwmNum 6
#define MEM_SIZE 256
- #define EXTERNAL_EEPROM //24AAXX/24LCXX/24FCXX EEPROM
+ #define STM32_EEPROM //24AAXX/24LCXX/24FCXX EEPROM
#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
DigitalInOut pwmpin[] = { P0_14,P0_2,P0_23,P0_17 };
DigitalOut led1(P0_21);
// DigitalOut led2(P0_21);
InterruptIn ch1(P0_9);
PulseWidthCounter ch[5] = { P0_8,P0_10,P0_7,P0_22,P1_15 };
-// SoftPWM pwm[4] = { P0_14,P0_2,P0_23,P0_17 };
- PulseOut pwm[6] = { P0_14,P0_2,P0_23,P0_17,p0_20,p015 };
- Ticker Tpwm;
- #define SOFTPWM
- SoftPWM buzz(P1_19);
+ PwmOut pwm[4] = { P0_14,P0_2,P0_23,P0_17 };
+// SoftPWM buzz(P1_19);
I2cPeripherals i2c(P0_5,P0_4); //sda scl
SerialLcd lcd(P0_19,P0_18);
+ #define PwmNum 4
#define MEM_SIZE 256
#define TARGET_EEPROM_ADDRESS 64
-// #define EXTERNAL_EEPROM
#define INTERNAL_EEPROM
IAP iap;
#elif defined(TARGET_LPC1114) // LPC1114
- DigitalInOut pwmpin[] = { dp1,dp2,dp18,dp24 };
+// DigitalInOut pwmpin[] = { dp1,dp2,dp18,dp24 };
DigitalOut led1(dp28);
InterruptIn ch1(dp4);
- PulseWidthCounter ch[5] = { dp9,dp10,dp11,dp13,dp26 };
-// SoftPWM pwm[4] = { dp1,dp2,dp18,dp24 };
- PulseOut pwm[6] = { dp1,dp2,dp18,dp24,dp17,dp6 };
- Ticker Tpwm;
- #define SOFTPWM
- SoftPWM buzz(dp25);
+// PulseWidthCounter ch[5] = { dp9,dp10,dp11,dp13,dp26 };
+ PwmOut pwm[4] = { dp1,dp2,dp18,dp24 };
+// SoftPWM buzz(dp25);
I2cPeripherals i2c(dp5,dp27); //sda scl
SerialLcd lcd(dp16,dp15);
+ #define PwmNum 4
+ #define MEM_SIZE 256
+ #define EXTERNAL_EEPROM
+#elif defined(TARGET_TEENSY3_1) // Teensy3.1
+ DigitalOut led1(D13);
+ InterruptIn ch1(D2);
+ PwmOut pwm[6] = { D3,D4,D5,D6,d20,D21 };
+ I2cPeripherals i2c(D18,D19); //sda scl
+ SerialLcd lcd(D3,D4); //TX,RX
+ #define PwmNum 6
#define MEM_SIZE 256
#define EXTERNAL_EEPROM
#endif
@@ -99,13 +149,13 @@
Timer CurTime;
//Timer ElapTime;
Timer CycleTime;
-Timer FlyghtTime;
+//Timer FlyghtTime;
config conf;
//PID pid[4];
-Limiter throLimit = 100;
-Limiter gyroLimit[3] = {300,300,300};
-Limiter accLimit[3] = {0.5,0.5,0.5};
-Limiter pwmLimit[4] = {50,50,50,50};
+//Limiter throLimit = 100;
+Limiter gyroLimit[3] = {0.9,0.9,0.9};
+Limiter accLimit[3] = {0.95,0.95,0.95};
+//Limiter pwmLimit[4] = {50,50,50,50};
//PID height;
float TotalTime = 0;;
int channel = 0;
@@ -153,7 +203,7 @@
float Rdata;
void initialize();
-void FlashLED(int );
+void FlashLED(int ,float tm=0.1);
void SetUp();
void SetUpPrompt(config&,I2cPeripherals&);
void PWM_Out(bool);
@@ -172,12 +222,8 @@
void LCD_printf(char *);
void LCD_cls();
void LCD_locate(int,int);
-#ifdef SOFTPWM
-void Tpwm_interrupt()
-{
- for ( int i=0; i<4; i++ ) pwm[i].start();
-}
-#endif
+void wait(float);
+
void PulseCheck() //cppm信号のチェック
{
channel++;
@@ -206,6 +252,18 @@
initialize();
Get_Stick_Pos();
+#ifdef DEBUG
+ char str[18];
+ while ( THR > 1800 ) {
+ LCD_locate(0,0);
+ sprintf(str,"TR=%4d,AL=%4d",THR,AIL);
+ LCD_printf(str);
+ LCD_locate(0,1);
+ sprintf(str,"EL=%4d,RD=%4d",ELE,RUD);
+ LCD_printf(str);
+ Get_Stick_Pos();
+ }
+#endif
while ( Stick[COL] > Thro_Zero || conf.StartMode == 'C'
|| ( conf.Model_Type == Quad_3D && Stick[GAIN] < 0 ) ) //Shrottol Low
{
@@ -231,12 +289,12 @@
{
if ( i > 100 ) //wait 2 sec
{
- FlyghtTime.stop();
+// FlyghtTime.stop();
if ( Stick[PIT] < -Stick_Limit ) { //Elevetor Down
loop_cnt = 0;
FlashLED(5);
- for ( int x=0; x<6; x++ ) {
+ for ( int x=0; x<PwmNum; x++ ) {
pwm[x].pulsewidth_us(PWM_Init[conf.Model_Type][x]);
}
i2c.start(conf.LCD_Contrast);
@@ -258,39 +316,38 @@
void initialize()
{
- buzz.period_us(400);
i2c.start(conf.LCD_Contrast);
- for ( int i=0;i<6;i++ ) pwm[i].pulsewidth_us(0);
+ for ( int i=0;i<PwmNum;i++ ) pwm[i].pulsewidth_us(0);
ReadConfig(); //config.inf file read
channel = 0;
+//#if defined(TARGET_LPC1114) // LPC1114
+
ch1.rise(&PulseCheck); //input pulse count
wait(0.2);
if ( channel > 50 ) {
+ FlashLED(50,0.02);
ch1.rise(&PulseAnalysis);
- InPulseMode = 'S';
- }
+ InPulseMode = 'S'; }
else InPulseMode = 'P';
+//#endif
led1 = 0;
CycleTime.start();
- throLimit.differential(conf.Thro_Limit_Val);
- throLimit.rate(conf.Thro_Limit_Rate);
-#ifdef SOFTPWM
- Tpwm.attach_us(&Tpwm_interrupt,conf.PWM_Interval);
-#endif
- Base_Press = (float)i2c.pressure() / 4096;
- FlashLED(3);
+// throLimit.differential(conf.Thro_Limit_Val);
+// throLimit.rate(conf.Thro_Limit_Rate);
+// Base_Press = (float)i2c.pressure() / 4096;
+ FlashLED(10,0.05);
}
-void FlashLED(int cnt)
+void FlashLED(int cnt,float tm)
{
for ( int i = 0 ; i < cnt ; i++ ) {
led1 = !led1;
- buzz = 0.5f;
- wait(0.1);
+// buzz = 0.5f;
+ wait(tm);
led1 = !led1;
- buzz = 0.0f;
- wait(0.1);
+// buzz = 0.0f;
+ wait(tm);
}
}
@@ -321,32 +378,36 @@
char *send;
char *recv;
int i;
+ char buf[MEM_SIZE];
config *conf_ptr;
if ( sizeof(config) > MEM_SIZE ) {
- LCD_printf("config size over");
+// pc.printf("config size over");
wait(3);
return;
}
//#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
-#if defined(INTERNAL_EEPROM) || defined(EXTERNAL_EEPROM)
- char buf[MEM_SIZE];
+#if defined(INTERNAL_EEPROM) || defined(EXTERNAL_EEPROM) || defined(STM32_EEPROM)
#if defined(INTERNAL_EEPROM)
iap.read_eeprom( (char*)TARGET_EEPROM_ADDRESS, buf, MEM_SIZE );
- #else
+ #elif defined(EXTERNAL_EEPROM)
//External Flash Memory Wreite
short pos = 0;
if ( i2c.read_EEPROM(pos,buf,MEM_SIZE) != 0 ) {
while(1) {
FlashLED(3);
wait(0.5);
-return;
}
}
+ #else //STM32 emulate eeprom
+// EEPROM_Read(0,buf,MEM_SIZE)
+ readEEPROM(0,(uint32_t*)buf,sizeof(config));
#endif
send = buf;
+ conf_ptr = (config*)buf;
+//pc.printf("rev=%f",conf_ptr->Revision);
recv = (char*)&conf;
- conf_ptr = (config*)buf;
+// conf_ptr = (config*)buf;
if ( conf_ptr->Revision == conf.Revision && conf_ptr->Struct_Size == sizeof(config) ) {
for ( i=0;i<sizeof(config);i++ ) recv[i] = send[i];
return;
@@ -376,11 +437,11 @@
fwrite(&conf,1,sizeof(config),fp);
fclose(fp);
#else
- char mem[MEM_SIZE];
+ char mem[MEM_SIZE]= " ";;
char *send;
int i;
if ( sizeof(config) > MEM_SIZE ) {
- LCD_printf("config size over");
+// pc.printf("config size over");
wait(3);
return;
}
@@ -388,26 +449,38 @@
for ( i=0;i<sizeof(config);i++ ) mem[i] = send[i];
for ( i=sizeof(config);i<MEM_SIZE;i++ ) mem[i] = 0x00;
//#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501)
-#if defined(INTERNAL_EEPROM)
- iap.write_eeprom( mem, (char*)TARGET_EEPROM_ADDRESS, MEM_SIZE );
-#elif defined(EXTERNAL_EEPROM)
+ #if defined(INTERNAL_EEPROM)
+ iap.write_eeprom( mem, (char*)TARGET_EEPROM_ADDRESS, MEM_SIZE );
+ #elif defined(EXTERNAL_EEPROM)
//External Flash Memory Wreite
- short pos = 0;
- i2c.write_EEPROM( pos,mem,MEM_SIZE) ;
-#else
- iap.prepare( TARGET_SECTOR, TARGET_SECTOR );
- iap.erase( TARGET_SECTOR, TARGET_SECTOR );
- iap.prepare( TARGET_SECTOR, TARGET_SECTOR );
- iap.write( mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE );
-#endif
+ short pos = 0;
+ i2c.write_EEPROM( pos,mem,MEM_SIZE) ;
+ #elif defined(STM32_EEPROM)
+// EEPROM_Write(0,buf,MEM_SIZE);
+ enableEEPROMWriting();
+ writeEEPROM(0, (uint32_t *)mem,sizeof(config));
+ disableEEPROMWriting();
+// pc.printf("rev=%f,rev=%d",((config*)mem)->Revision,readEEPROMWord(0));
+ #else
+ iap.prepare( TARGET_SECTOR, TARGET_SECTOR );
+ iap.erase( TARGET_SECTOR, TARGET_SECTOR );
+ iap.prepare( TARGET_SECTOR, TARGET_SECTOR );
+ iap.write( mem, sector_start_adress[ TARGET_SECTOR ], MEM_SIZE );
+ #endif
+ for ( i=0; i<4; i++ ) {
+ FlashLED(10,0.03);
+ wait(0.5);
+ }
#endif
}
void Get_Stick_Pos(void)
{
+#ifndef TARGET_LPC1114 // LPC1114
if ( InPulseMode == 'P' ) {
for (int i=0;i<5;i++) CH[i] = ch[i].count;
}
+#endif
// Stick_Save[ROL] = Stick[ROL];
// Stick_Save[PIT] = Stick[PIT];
// Stick_Save[YAW] = Stick[YAW];
@@ -543,8 +616,8 @@
TotalTime += interval;
if ( TotalTime > 0.5f ) {
led1 = !led1;
- if ( ( !buzz ) && ( (float)conf.Flight_Time < FlyghtTime.read() ) ) buzz=0.5;
- else buzz=0.0;
+ // if ( ( !buzz ) && ( (float)conf.Flight_Time < FlyghtTime.read() ) ) buzz=0.5;
+ // else buzz=0.0;
TotalTime = 0;
}
@@ -664,7 +737,7 @@
break;
}
j = conf.Model_Type;
- for ( i=0; i<6; i++ ) {
+ for ( i=0; i<PwmNum; i++ ) {
if ( M[i] > Pulse_Max ) M[i] = Pulse_Max;
if ( M[i] < Pulse_Min ) M[i] = Pulse_Min;
if ( Servo_idx[j][i] == 1 )
@@ -685,7 +758,7 @@
}
if ( mode ) {
// h = conf.Stick_Ref[THR];
- for ( i=0;i<6;i++ ) {
+ for ( i=0;i<PwmNum;i++ ) {
// while ( !pwmpin[i] );
if ( conf.PWM_Mode == 1 )
pwm[i].pulsewidth_us(M[i]);
@@ -699,7 +772,7 @@
void ESC_SetUp(void) {
while(1) {
Get_Stick_Pos();
- for ( int i=0;i<4;i++ ) pwm[i].pulsewidth_us(conf.Stick_Ref[COL]+Stick[COL]);
+ for ( int i=0;i<PwmNum;i++ ) pwm[i].pulsewidth_us(conf.Stick_Ref[COL]+Stick[COL]);
wait(0.015);
}
}
@@ -707,22 +780,17 @@
void Flight_SetUp(void)
{
int i;
-#ifdef SOFTPWM
- Tpwm.detach();
- Tpwm.attach_us(&Tpwm_interrupt,conf.PWM_Interval);
-#else
- for ( i=0;i<6;i++ ) pwm[i].pulsewidth_us(0);
- for ( i=0;i<6;i++ ) pwm[i].period_us(conf.PWM_Interval);
-#endif
- for ( i=0; i<6; i++ ) {
+ for ( i=0;i<PwmNum;i++ ) pwm[i].pulsewidth_us(0);
+ for ( i=0;i<PwmNum;i++ ) pwm[i].period_us(conf.PWM_Interval);
+ for ( i=0; i<PwmNum; i++ ) {
pwm[i].pulsewidth_us(PWM_Init[conf.Model_Type][i]);
}
hov_control = false;
- throLimit.differential(conf.Thro_Limit_Val);
- throLimit.rate(conf.Thro_Limit_Rate);
+// throLimit.differential(conf.Thro_Limit_Val);
+// throLimit.rate(conf.Thro_Limit_Rate);
Angle[ROL]=Angle[PIT]=Angle[YAW]=0;
loop_cnt = 0;
- FlyghtTime.start();
+// FlyghtTime.start();
CycleTime.start();
pid_interval = 0;
Stick_Save[COL] = Stick[COL];
@@ -743,8 +811,13 @@
void LCD_printf(char* str)
{
- lcd.printf(str);
- i2c.printf(str);
+ lcd.write(str);
+ i2c.write_lcd(str);
+}
+
+void wait(float tm)
+{
+ wait_us(tm*1000000);
}
;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sun Feb 21 05:14:57 2021 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#bfde5aa1e74802771eaeacfa74789f71677325cb
--- a/mbed.bld Tue Apr 28 01:48:21 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file