1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Initial Arduino IDE based on Processing.

This commit is contained in:
David A. Mellis
2005-08-25 21:06:28 +00:00
commit 9fc5aa63f6
373 changed files with 71081 additions and 0 deletions

View File

@ -0,0 +1,4 @@
/megaio.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/megaio.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
/megaioreg.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
D

View File

@ -0,0 +1 @@
Arduino/wiringlite/avrlib/megaio

View File

@ -0,0 +1 @@
:ext:mbanzi@cvs.arduino.berlios.de:/cvsroot/arduino

View File

@ -0,0 +1,175 @@
/*! \file megaio.c \brief MegaIO Control/Access function library. */
//*****************************************************************************
//
// File Name : 'megaio.c'
// Title : MegaIO Control/Access function library
// Author : Pascal Stang - Copyright (C) 2004
// Created : 5/18/2004
// Revised : 5/18/2004
// Version : 0.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#include "buffer.h" // include buffer support
#include "i2c.h" // include I2C functions
#include "megaio/megaioreg.h" // include MegaIO register definitions
#include "megaio.h"
// MegaIO local receive buffer size
#define MEGAIO_UART_RX_BUFFER_SIZE 0x80
// MegaIO local receive buffer data array
static char megaioUartRxData[MEGAIO_UART_RX_BUFFER_SIZE];
// MegaIO local receive buffer
cBuffer megaioUartRxBuffer;
//! initialize the MegaIO interface
u08 megaioInit(void)
{
// initialize the UART receive buffer
bufferInit(&megaioUartRxBuffer, megaioUartRxData, MEGAIO_UART_RX_BUFFER_SIZE);
// initialize i2c interface
i2cInit();
i2cSetBitrate(30);
// check for presence of megaio chip
if( megaioReadReg(MEGAIOREG_IDSTRING, 1) == 'M' )
{
// megaio responded correctly
// initialization succeeded
return TRUE;
}
else
{
// megaio responded incorrectly
// initialization failed
return FALSE;
}
}
//! write an 8-32 bit number to a MegaIO register
void megaioWriteReg(unsigned char regnum, unsigned char nbytes, unsigned long data)
{
u08 packet[5];
// construct I2c data packet
// first byte is register address
// following bytes are the data that will be written to that register
packet[0] = regnum;
packet[1] = data;
packet[2] = data>>8;
packet[3] = data>>16;
packet[4] = data>>24;
// send 2 bytes (register and data) to MegaIO
i2cMasterSend(MEGAIO_I2C_ADDR, 1+nbytes, packet);
}
//! read an 8-32 bit number from a MegaIO register
unsigned long megaioReadReg(unsigned char regnum, unsigned char nbytes)
{
unsigned long data = 0;
// first select the register by writing 1 byte (register)
i2cMasterSend(MEGAIO_I2C_ADDR, 1, &regnum);
// then read n byte(s) from the selected MegaIO register
i2cMasterReceive(MEGAIO_I2C_ADDR, nbytes, (u08*)&data);
// return the results
return data;
}
//! set the baudrate of the megaio serial port
void megaioSetBaudRate(u32 baudrate)
{
megaioWriteReg(MEGAIOREG_UARTBAUD, 4, baudrate);
}
//! send a byte out the megaio serial port
void megaioSendByte(u08 data)
{
megaioWriteReg(MEGAIOREG_UARTDATA, 1, data);
}
//! get a byte from the megaio serial port
int megaioGetByte(void)
{
u08 data;
// check the number of bytes in the megaio receive buffer
if( megaioReadReg(MEGAIOREG_UARTRXBUFBYTES, 1) )
{
// one or more bytes are available
// get first byte
data = megaioReadReg(MEGAIOREG_UARTDATA, 1);
return data;
}
else
{
// no bytes were available
// (no bytes have arrived and are waiting to be read)
return -1;
}
}
//! returns the receive buffer structure
cBuffer* megaioGetRxBuffer(void)
{
u08 nbytes;
// get the number of bytes waiting in the MegaIO buffer
nbytes = megaioReadReg(MEGAIOREG_UARTRXBUFBYTES, 1);
// get all available bytes from the MegaIO chip
// and add them to the receive buffer
while(megaioReadReg(MEGAIOREG_UARTRXBUFBYTES, 1))
{
bufferAddToEnd(&megaioUartRxBuffer, megaioReadReg(MEGAIOREG_UARTDATA, 1));
nbytes--;
}
// return rx buffer pointer
return &megaioUartRxBuffer;
}
//! turn on megaio PWM and set for bitRes resolution
void megaioPWMInit(u08 bitRes)
{
megaioWriteReg(MEGAIOREG_PWM1CTRL, 1, bitRes);
}
//! turn off megaio PWM
void megaioPWMOff(void)
{
megaioWriteReg(MEGAIOREG_PWM1CTRL, 1, 0);
}
//! set megaio PWM1A duty cycle
void megaioPWMASet(u16 pwmDuty)
{
megaioWriteReg(MEGAIOREG_PWM1ADUTY, 2, pwmDuty);
}
//! set megaio PWM1B duty cycle
void megaioPWMBSet(u16 pwmDuty)
{
megaioWriteReg(MEGAIOREG_PWM1BDUTY, 2, pwmDuty);
}
//! set megaio prescaler division rate
void megaioSetPrescaler(u08 prescaleDiv)
{
megaioWriteReg(MEGAIOREG_PWM1FREQ, 1, prescaleDiv);
}
//! do A/D conversion on channel [ch] and return result
u16 megaioA2DConvert(u08 ch)
{
// set channel
megaioWriteReg(MEGAIOREG_ADCCHSEL, 1, ch);
// start single conversion
megaioWriteReg(MEGAIOREG_ADCCTRL, 1, 0x01);
// wait for conversion to be complete
while( megaioReadReg(MEGAIOREG_ADCCTRL, 1) );
// get result and return it
return megaioReadReg(MEGAIOREG_ADCRESULT, 2);
}

View File

@ -0,0 +1,57 @@
/*! \file megaio.h \brief MegaIO Control/Access function library. */
//*****************************************************************************
//
// File Name : 'megaio.h'
// Title : MegaIO Control/Access function library
// Author : Pascal Stang - Copyright (C) 2004
// Created : 5/18/2004
// Revised : 5/18/2004
// Version : 0.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef MEGAIO_H
#define MEGAIO_H
#include "megaio/megaioreg.h" // include MegaIO register definitions
// defines
// function prototypes
//! initialize the MegaIO interface
u08 megaioInit(void);
//! write an 8-32 bit number to a MegaIO register
void megaioWriteReg(unsigned char regnum, unsigned char nbytes, unsigned long data);
//! read an 8-32 bit number from a MegaIO register
unsigned long megaioReadReg(unsigned char regnum, unsigned char nbytes);
//! set the baudrate of the MegaIO serial port
void megaioSetBaudRate(u32 baudrate);
//! send a byte out the MegaIO serial port
void megaioSendByte(u08 data);
//! get a byte from the MegaIO serial port
int megaioGetByte(void);
//! get a complete receive buffer with data from MegaIO serial port
cBuffer* megaioGetRxBuffer(void);
//! turn on MegaIO PWM and set for bitRes resolution
void megaioPWMInit(u08 bitRes);
//! turn off MegaIO PWM
void megaioPWMOff(void);
//! set MegaIO PWM1A duty cycle
void megaioPWMASet(u16 pwmDuty);
//! set MegaIO PWM1B duty cycle
void megaioPWMBSet(u16 pwmDuty);
//! set MegaIO prescaler division rate
void megaioSetPrescaler(u08 prescaleDiv);
//! do A/D conversion on channel [ch] and return result
u16 megaioA2DConvert(u08 ch);
#endif

View File

@ -0,0 +1,88 @@
/*! \file megaioreg.h \brief MegaIO register definitions. */
//*****************************************************************************
//
// File Name : 'megaioreg.h'
// Title : MegaIO register definitions
// Author : Pascal Stang - Copyright (C) 2003
// Created : 2003.07.16
// Revised : 2003.07.17
// Version : 0.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
#ifndef MEGAIOREG_H
#define MEGAIOREG_H
// define MEGAIO I2C address
#define MEGAIO_I2C_ADDR 0x4C
// define MEGAIO registers
// General Registers
#define MEGAIOREG_IDSTRING 0x00
// UART Registers
#define MEGAIOREG_UARTDATA 0x10
#define MEGAIOREG_UARTBAUD 0x14
#define MEGAIOREG_UARTBAUDSEL 0x15
#define MEGAIOREG_UARTRXBUFBYTES 0x18
#define MEGAIOREG_UARTTXBUFBYTES 0x19
// PWM Registers
#define MEGAIOREG_PWM1CTRL 0x20
#define MEGAIOREG_PWM1FREQ 0x21
#define MEGAIOREG_PWM1ADUTY 0x24
#define MEGAIOREG_PWM1BDUTY 0x25
// A/D Converter Registers
#define MEGAIOREG_ADCCTRL 0x30
#define MEGAIOREG_ADCCHSEL 0x31
#define MEGAIOREG_ADCRESULT 0x32
// PORT Access Registers
#define MEGAIOREG_PORTA 0x40
#define MEGAIOREG_DDRA 0x41
#define MEGAIOREG_PINA 0x42
#define MEGAIOREG_PORTB 0x43
#define MEGAIOREG_DDRB 0x44
#define MEGAIOREG_PINB 0x45
#define MEGAIOREG_PORTC 0x46
#define MEGAIOREG_DDRC 0x47
#define MEGAIOREG_PINC 0x48
#define MEGAIOREG_PORTD 0x49
#define MEGAIOREG_DDRD 0x4A
#define MEGAIOREG_PIND 0x4B
#define MEGAIOREG_PORTE 0x4C
#define MEGAIOREG_DDRE 0x4D
#define MEGAIOREG_PINE 0x4E
#define MEGAIOREG_PORTF 0x4F
#define MEGAIOREG_DDRF 0x50
#define MEGAIOREG_PINF 0x51
// Direct Access Registers
#define MEGAIOREG_DIRECTIO 0x80
#define MEGAIOREG_DIRECTMEM 0x81
// define MEGAIO register values
#define UARTBAUDSEL_300 0x00
#define UARTBAUDSEL_600 0x01
#define UARTBAUDSEL_1200 0x02
#define UARTBAUDSEL_2400 0x03
#define UARTBAUDSEL_4800 0x04
#define UARTBAUDSEL_9600 0x05
#define UARTBAUDSEL_19200 0x06
#define UARTBAUDSEL_38400 0x07
#define UARTBAUDSEL_115200 0x08
#define PWM1FREQ_STOP 0x00
#define PWM1FREQ_MAX 0x01
#define PWM1FREQ_DIV8 0x02
#define PWM1FREQ_DIV64 0x03
#define PWM1FREQ_DIV256 0x04
#define PWM1FREQ_DIV1024 0x05
#endif