Commit 2c732236 authored by Jake Read's avatar Jake Read

add circuit, datasheets

parent 137aa61c
Pipeline #2628 passed with stage
in 4 seconds
......@@ -132,7 +132,9 @@ If you have errors, make sure your pinouts are correct, your board has power, an
#### Including Example Code
I've build a few 'libraries' for all of these chips. Each is a .c and .h file. To include them in your project, follow these steps.
I've build a few 'libraries' for all of these chips. Each is a .c and .h file. They are located in this repo, [here](xmega-atk-libs), but I recommend you only use them for reference. To see how they come together in applications, you can poke around in endpoints [for the automatakit project](https://gitlab.cba.mit.edu/jakeread/automatakit).
To include external files in your project, follow these steps.
In the Atmel Studio 'Solution Explorer' (might not be open, go to View -> Solution Explorer), right-click on the Solution (mkembedded-example in this case) and do Add -> Existing Item
......@@ -152,4 +154,10 @@ Now we should be ready to build the example:
## Example Circuitry
In in [this subdirectory](circuit) you'll find an example eagle schematic and
\ No newline at end of file
In in [this subdirectory](circuit) you'll find an example eagle schematic and board for a minimum breadboard-xmega that uses the XMEGA A4U Series.
![board](circuit/bbxmega/board.png)
![sch](circuit/bbxmega/schematic.png)
Make one, modify one, etc.
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
[Eagle]
Version="08 03 02"
Platform="Windows"
Globals="Globals"
Desktop="Desktop"
[Globals]
AutoSaveProject=1
UsedLibraryUrn="urn:adsk.eagle:library:217"
UsedLibraryUrn="urn:adsk.eagle:library:325"
UsedLibraryUrn="urn:adsk.eagle:library:371"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries/eagle/fab.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/jake/tag-connect-2030.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/jake/tag-connect-2050.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/sparkfun/SparkFun-Connectors.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/Comparators.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/Digital.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/FilterProducts.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/Misc.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/Opamps.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/Optos.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/PAsystem.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/PowerProducts.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/References.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/SpecialFunctions.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/capmeter.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/diode.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/lt-spice-simulation.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/lt-supply.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/rload.lbr"
UsedLibrary="C:/EAGLE 8.3.2/lbr/ltspice/sym.lbr"
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/marekr/borkedlabs-passives.lbr"
[Win_1]
Type="Schematic Editor"
Loc="0 0 1919 1016"
State=1
Number=2
File="bbxmega.sch"
View="-13.5313 5.97904 167.1 132.776"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
DimensionWidths=" 0 0.127 0.254 0.1 0.26 0.13"
DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=0
WireBendSet=31
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=0
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
DimensionUnit=1
DimensionPrecision=2
DimensionShowUnit=0
PinDirection=3
PinFunction=0
PinLength=2
PinVisible=3
SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=91
Views=" 1: -13.5313 5.97904 167.1 132.776"
Sheet="1"
[Win_2]
Type="Board Editor"
Loc="0 0 1919 1016"
State=1
Number=1
File="bbxmega.brd"
View="-1.29872 8.23325 42.8321 44.005"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
DimensionWidths=" 0 0.127 0.254 0.1 0.26 0.13"
DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=1
WireBendSet=0
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=1
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
DimensionUnit=1
DimensionPrecision=2
DimensionShowUnit=0
PinDirection=3
PinFunction=0
PinLength=2
PinVisible=3
SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=1
[Win_3]
Type="Control Panel"
Loc="0 0 1919 1039"
State=1
Number=0
[Desktop]
Screen="3840 1080"
Window="Win_1"
Window="Win_2"
Window="Win_3"
/*
* fastmath.c
*
* Created: 6/20/2018 12:38:38 PM
* Author: Jake
*/
int fastModulo(int dividend, int divisor){
// divisor must be a power of 2!
return dividend & (divisor - 1);
}
\ No newline at end of file
/*
* fastmath.h
*
* Created: 6/20/2018 12:35:50 PM
* Author: Jake
*/
#ifndef FASTMATH_H_
#define FASTMATH_H_
int fastModulo(int dividend, int divisor);
#endif /* FASTMATH_H_ */
\ No newline at end of file
/*
* pin.c
*
* Created: 6/18/2018 12:22:50 PM
* Author: Jake
*/
#include "pin.h"
void pin_init(pin_t *pin, PORT_t *port, uint8_t pin_bm, uint8_t pin_pos, uint8_t inout){
pin->port = port;
pin->pin_bm = pin_bm;
pin->pin_pos = pin_pos;
if(inout){
pin_output(pin);
} else {
pin_input(pin);
}
}
void pin_output(pin_t *pin){
pin->port->DIRSET = pin->pin_bm;
}
void pin_set(pin_t *pin){
pin->port->OUTSET = pin->pin_bm;
}
void pin_clear(pin_t *pin){
pin->port->OUTCLR = pin->pin_bm;
}
void pin_toggle(pin_t *pin){
pin->port->OUTTGL = pin->pin_bm;
}
void pin_input(pin_t *pin){
pin->port->DIRCLR = pin->pin_bm;
}
void pin_pullup(pin_t *pin){
// ? how to access PIN0CTRL, etc?
}
void pin_pulldown(pin_t *pin){
//
}
uint8_t pin_read(pin_t *pin){
return (pin->port->IN & pin->pin_bm);
}
\ No newline at end of file
/*
* pin.h
*
* Created: 6/18/2018 12:22:58 PM
* Author: Jake
*/
#ifndef PIN_H_
#define PIN_H_
#include "avr/io.h"
typedef struct {
PORT_t *port;
uint8_t pin_bm;
uint8_t pin_pos;
}pin_t;
void pin_init(pin_t *pin, PORT_t *port, uint8_t pin_bm, uint8_t pin_pos, uint8_t inout);
void pin_output(pin_t *pin);
void pin_set(pin_t *pin);
void pin_clear(pin_t *pin);
void pin_toggle(pin_t *pin);
void pin_input(pin_t *pin);
void pin_pullup(pin_t *pin);
void pin_pulldown(pin_t *pin);
uint8_t pin_read(pin_t *pin);
#endif /* PIN_H_ */
\ No newline at end of file
/*
* ringbuffer.c
*
* Created: 2/7/2018 11:39:44 AM
* Author: Jake
*/
#include "ringbuffer.h"
#include "fastmath.h"
uint8_t rb_init(ringbuffer_t *rb){
rb->size = RINGBUFFER_SIZE;
// stuck with this, due to not having malloc, wall of skill
//rb->buffer = malloc(size);
rb_reset(rb);
return 1;
}
uint8_t rb_reset(ringbuffer_t *rb){
if(rb){
rb->head = 0;
rb->tail = 0;
return 1;
} else {
return 0;
}
}
uint8_t rb_empty(ringbuffer_t *rb){
return (rb->head == rb->tail);
}
uint8_t rb_full(ringbuffer_t *rb){
// read from tail, update at head
// if head is 'just behind' tail (in ring) we have no extra space: the
return fastModulo((rb->head + 1), RINGBUFFER_SIZE) == rb->tail;
}
uint8_t rb_freespace(ringbuffer_t *rb){
if(rb->head >= rb->tail){
return rb->size - (rb->head - rb->tail);
} else {
return rb->tail - rb->head - 1;
}
}
uint8_t rb_putchar(ringbuffer_t *rb, uint8_t data){
rb->buffer[rb->head] = data;
rb->head = fastModulo((rb->head + 1), RINGBUFFER_SIZE); // increment and loop about
return 1;
}
uint8_t rb_putdata(ringbuffer_t *rb, uint8_t *data, uint8_t size){
/*
if(rb_freespace(rb) >= size){
// rb_freespace, not working?
return 0;
} else {
*/
for(int i = 0; i < size; i ++){
rb_putchar(rb, data[i]);
}
return 1;
//}
}
uint8_t rb_get(ringbuffer_t *rb){
uint8_t data = rb->buffer[rb->tail];
rb->tail = fastModulo((rb->tail + 1), RINGBUFFER_SIZE);
return data;
}
/*
* ringbuffer.h
*
* Created: 2/7/2018 11:39:54 AM
* Author: Jake
*/
#ifndef RINGBUFFER_H_
#define RINGBUFFER_H_
/*
a ringbuffer,
s/o https://github.com/dhess/c-ringbuf
s/o https://embeddedartistry.com/blog/2017/4/6/circular-buffers-in-cc
s/o https://www.downtowndougbrown.com/2013/01/microcontrollers-interrupt-safe-ring-buffers/
*/
#include "avr/io.h"
#include <stdlib.h> // for size_t
#define RINGBUFFER_SIZE 256
typedef struct{
uint8_t buffer[256]; // static! big enough
size_t head;
size_t tail;
size_t size;
} ringbuffer_t;
uint8_t rb_init(ringbuffer_t *rb);
uint8_t rb_reset(ringbuffer_t *rb);
uint8_t rb_empty(ringbuffer_t *rb);
uint8_t rb_full(ringbuffer_t *rb);
uint8_t rb_freespace(ringbuffer_t *rb);
uint8_t rb_putchar(ringbuffer_t *rb, uint8_t data);
uint8_t rb_putdata(ringbuffer_t *rb, uint8_t *data, uint8_t size);
uint8_t rb_get(ringbuffer_t *rb);
#endif /* RINGBUFFER_H_ */
\ No newline at end of file
/*
* spiport.c
*
* Created: 2/7/2018 10:51:42 AM
* Author: Jake
*/
#include "spiport.h"
void spi_init(spiport_t *spi, USART_t *com, PORT_t *port, uint8_t miso_bm, uint8_t mosi_bm, uint8_t sck_bm, pin_t *csn){
spi->com = com;
spi->port = port;
spi->miso_bm = miso_bm;
spi->mosi_bm = mosi_bm;
spi->sck_bm = sck_bm;
spi->csn = csn;
}
void spi_start(spiport_t *spi, uint8_t cpha){
spi->port->DIRSET = spi->mosi_bm;
spi->port->DIRSET = spi->sck_bm;
spi->port->DIRCLR = spi->miso_bm;
// want BSEL 7 and BSCALE -4
spi->com->BAUDCTRLA = 0; //130;
spi->com->BAUDCTRLB = 1; //USART_BSCALE3_bm | USART_BSCALE2_bm | USART_BSCALE1_bm | USART_BSCALE0_bm;
spi->com->CTRLB = USART_TXEN_bm | USART_RXEN_bm;
spi->com->CTRLC = USART_CMODE_MSPI_gc; // set to master spi mode
if(cpha != 0){
spi->com->CTRLC |= (1 << 1); // in master spi mode, this bit is clock polarity
}
}
void spi_txchar_polled(spiport_t *spi, uint8_t data){
while(!(spi->com->STATUS & USART_DREIF_bm));
spi->com->DATA = data;
}
void spi_txchars_polled(spiport_t *spi, uint8_t *data, uint8_t length){
pin_clear(spi->csn);
for(int i = 0; i < length; i ++){
spi_txchar_polled(spi, data[i]);
spi->com->STATUS |= USART_TXCIF_bm; // clear transmit complete flag
}
while(!(spi->com->STATUS & USART_TXCIF_bm)); // wait for complete before
pin_set(spi->csn);
}
void spi_txrxchar_polled(spiport_t *spi, uint8_t data, uint8_t *rxdata){
// how to read?
}
\ No newline at end of file
/*
* spiport.h
*
* Created: 2/7/2018 10:51:52 AM
* Author: Jake
*/
#ifndef SPIPORT_H_
#define SPIPORT_H_
#include <avr/io.h>
#include "pin.h"
typedef struct{
USART_t *com;
PORT_t *port;
uint8_t miso_bm;
uint8_t mosi_bm;
uint8_t sck_bm;
pin_t *csn;
}spiport_t;
void spi_init(spiport_t *spi, USART_t *com, PORT_t *port, uint8_t miso_bm, uint8_t mosi_bm, uint8_t sck_bm, pin_t *csn);
void spi_start(spiport_t *spi, uint8_t cpha); // bits: 0: 8, 1: 32
void spi_txchar_polled(spiport_t *spi, uint8_t data);
void spi_txchars_polled(spiport_t *spi, uint8_t *data, uint8_t length);
void spi_txrxchar_polled(spiport_t *spi, uint8_t data, uint8_t *rxdata);
#endif /* SPIPORT_H_ */
\ No newline at end of file
/*
* uartport.c
*
* Created: 6/18/2018 12:12:32 PM
* Author: Jake
*/
#include "uartport.h"
#include "hardware.h"
void uart_init(uartport_t *up, USART_t *uart, PORT_t *port, uint8_t pinRX_bm, uint8_t pinTX_bm, ringbuffer_t *rbrx, ringbuffer_t *rbtx, pin_t *stlrx, pin_t *stltx){
up->uart = uart;
up->port = port;
up->pinRX_bm = pinRX_bm;
up->pinTX_bm = pinTX_bm;
up->rbrx = rbrx;
up->rbtx = rbtx;
up->stlrx = stlrx;
up->stltx = stltx;
}
void uart_start(uartport_t *up, uint8_t BAUDA, uint8_t BAUDB){
up->uart->BAUDCTRLA = BAUDA;
up->uart->BAUDCTRLB = BAUDB;
up->uart->CTRLA |= USART_RXCINTLVL_MED_gc | USART_TXCINTLVL_OFF_gc | USART_DREINTLVL_OFF_gc;
up->uart->CTRLB = USART_TXEN_bm | USART_RXEN_bm;
// should try that parity
up->uart->CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc;
up->port->DIRCLR = up->pinRX_bm;
up->port->DIRSET = up->pinTX_bm;
pin_set(up->stlrx);
pin_set(up->stltx);
}
void uart_sendchar_polled(uartport_t *up, uint8_t data){
while(!(up->uart->STATUS & USART_DREIF_bm));
up->uart->DATA = data;
}
void uart_sendchar_buffered(uartport_t *up, uint8_t data){
rb_putchar(up->rbtx, data);
pin_clear(up->stltx);
up->uart->CTRLA |= USART_DREINTLVL_MED_gc;
}
void uart_sendchars_buffered(uartport_t *up, uint8_t *data, uint8_t length){
rb_putdata(up->rbtx, data, length);
pin_clear(up->stltx);
up->uart->CTRLA |= USART_DREINTLVL_MED_gc;
}
void uart_rxhandler(uartport_t *up){
pin_clear(up->stlrx);
uint8_t data = up->uart->DATA;
rb_putchar(up->rbrx, data);
}
void uart_txhandler(uartport_t *up){
if(!rb_empty(up->rbtx)){
up->uart->DATA = rb_get(up->rbtx);
} else {
up->uart->CTRLA = USART_DREINTLVL_OFF_gc | USART_RXCINTLVL_MED_gc;
pin_set(up->stltx);
}
}
\ No newline at end of file
/*
* uartport.h
*
* Created: 6/18/2018 12:12:43 PM
* Author: Jake
*/
#ifndef UARTPORT_H_
#define UARTPORT_H_
#include "avr/io.h"
#include "ringbuffer.h"
#include "pin.h"
typedef struct{
USART_t *uart;
PORT_t *port;
uint8_t pinRX_bm;
uint8_t pinTX_bm;
ringbuffer_t *rbrx;
ringbuffer_t *rbtx;
pin_t *stlrx;
pin_t *stltx;
}uartport_t;
void uart_init(uartport_t *up, USART_t *uart, PORT_t *port, uint8_t pinRX_bm, uint8_t pinTX_bm, ringbuffer_t *rbrx, ringbuffer_t *rbtx, pin_t *stlrx, pin_t *stltx);
void uart_start(uartport_t *up, uint8_t BAUDA, uint8_t BAUDB);
void uart_sendchar_polled(uartport_t *up, uint8_t data);
void uart_sendchar_buffered(uartport_t *up, uint8_t data);
void uart_sendchars_buffered(uartport_t *up, uint8_t *data, uint8_t length);
void uart_rxhandler(uartport_t *up);
void uart_txhandler(uartport_t *up);
#endif /* UARTPORT_H_ */
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment