1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-14 04:16:05 +01:00

Actionneurs

Partie Robotech hors-projet
This commit is contained in:
Geoffrey Frogeye 2018-05-08 00:45:08 +02:00
parent a6179781e0
commit 935d1054a7
92 changed files with 7037 additions and 1593 deletions

6
.gitmodules vendored
View file

@ -7,3 +7,9 @@
[submodule "raspberrypi/buildroot"]
path = raspberrypi/buildroot
url = /home/geoffrey/buildroot
[submodule "arduino/lib/AX12A"]
path = arduino/lib/AX12A
url = https://github.com/ThingType/AX-12A-servo-library.git
[submodule "Servo"]
path = arduino/lib/Servo
url = https://github.com/arduino-libraries/Servo.git

16
arduino/.gitignore vendored
View file

@ -1,16 +0,0 @@
FreeRTOSv9.0.0/*
*.zip
*.o
*.lst
*.d
*.hex
*.eep
*.obj
*.elf
*.map
*.obj
*.a90
*.sym
*.lnk
*.lss

View file

@ -1,106 +0,0 @@
#include "AC.h"
void registerRxHandlerAC(unsigned char code, rxHandler handler)
{
rxHandlersAC[code] = handler;
}
ISR(USART0_UDRE_vect)
{
// When a transmit is ready to be done again
UDR0 = *toSendAC;
toSendAC++;
toSendSizeAC--;
if (toSendSizeAC <= 0) {
UCSR0B &= ~(1 << UDRIE0);
TaskHandle_t holder = xSemaphoreGetMutexHolder(sSendAC);
if (holder != NULL) {
vTaskNotifyGiveFromISR(holder, NULL);
}
}
}
void sendAC(unsigned char code, void* data, size_t size)
{
xSemaphoreTake(sSendAC, portMAX_DELAY);
toSendAC = &code;
toSendSizeAC = sizeof(code);
UCSR0B |= (1 << UDRIE0);
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
if (size > 0) {
toSendAC = data;
toSendSizeAC = size;
UCSR0B |= (1 << UDRIE0);
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
}
xSemaphoreGive(sSendAC);
}
ISR(USART0_RX_vect)
{
// When a character is received
vTaskNotifyGiveFromISR(tReaderAC, NULL);
}
unsigned char readByteAC()
{
while (!bit_is_set(UCSR0A, RXC0)) {
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
}
unsigned char c = UDR0;
return c;
}
void readAC(void* data, size_t size)
{
unsigned char* p = data;
for (int i = 0; i < size; i++) {
*p = readByteAC();
p++;
}
}
void TaskReaderAC(void* pvParameters)
{
(void)pvParameters;
unsigned char code;
for (;;) {
code = readByteAC();
rxHandler handler = rxHandlersAC[code];
if (handler != NULL) {
handler();
} else {
struct A2CD_ERRs err = { ERR_UNKNOWN_CODE };
sendAC(A2CD_ERR, &err, sizeof(err));
}
}
}
void onC2AD_PING()
{
sendAC(C2AD_PING, NULL, 0);
}
void configureAC()
{
/* Set baud rate */
UBRR0 = AC_PRESCALER;
/* Set off UART baud doubler */
UCSR0A &= ~(1 << U2X0);
/* Enable transmitter & receiver with interrupts */
UCSR0B = (1 << RXCIE0 | 1 << TXEN0 | 1 << RXEN0);
/* Set 8 bits character and 1 stop bit */
UCSR0C = (1 << UCSZ01 | 1 << UCSZ00);
for (int i = 0; i < 256; i++) {
rxHandlersAC[i] = NULL;
}
sSendAC = xSemaphoreCreateMutex();
xTaskCreate(TaskReaderAC, "TaskReaderAC", 128, NULL, 2, &tReaderAC);
registerRxHandlerAC(C2AD_PING, onC2AD_PING);
}

View file

@ -1,35 +0,0 @@
/*
* Définition des fonctions utilisées pour échager entre l'Arduino et le chef
*/
#ifndef __AC_H_
#define __AC_H_
#include <FreeRTOS.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <queue.h>
#include <semphr.h>
#include <stdlib.h>
#include <task.h>
#include "ACsignals.h"
#define CPU_FREQ 16000000UL
#define AC_PRESCALER CPU_FREQ / (AC_BAUDRATE << 4) - 1
TaskHandle_t tReaderAC;
SemaphoreHandle_t sSendAC;
unsigned char* toSendAC;
size_t toSendSizeAC;
typedef void (*rxHandler)(void);
rxHandler rxHandlersAC[256];
void registerRxHandlerAC(unsigned char code, rxHandler handler); // À utiliser après configureAC();
void sendAC(unsigned char code, void* data, size_t size);
unsigned char readByteAC(); // À utiliser uniquement depuis un rxHandler
void readAC(void* data, size_t size); // À utiliser uniquement depuis un rxHandler
void TaskReaderAC(void* pvParameters); // Privé
void configureAC();
#endif

View file

@ -1,73 +0,0 @@
/*
* Définition des signaux échagés entre l'Arduino et le chef
*/
#ifndef __ACSIGNALS_H_
#define __ACSIGNALS_H_
#include "AFsignals.h"
#define AC_BAUDRATE 9600UL
// Structures used everywhere
struct __attribute__ ((packed)) position {
float x;
float y;
float o;
};
// D: Direct
// Sens naturel : Envoi de donnée
// Sens inverse : Accusé de réception
// I: Indirect
// Sens inverse : Demande de donnée
// Sens naturel : Envoi de donnée
// T: Trigger
// Sens inverse : Paramètrage du trigger
// Sens naturel : Envoi de trigger
// Chef → Arduino
// Pour le debug
#define C2AD_PING 'P'
// Arrête tous les actionneurs
#define C2AD_STOP 'S'
// Stoppe les roues
#define C2AD_BRAKE 'B'
// Laisse les roues libres
#define C2AD_FREE 'F'
// Donne une destination
#define C2AD_GOTO 'G'
#define C2AD_GOTOs position
// Peut-être o à NaN ou autre valeur spécifique si indifférent
// Arduino → Chef
// Erreur quelconque
#define A2CD_ERR 'E'
struct __attribute__ ((packed)) A2CD_ERRs {
unsigned char code;
};
#define ERR_UNKNOWN_CODE 'C'
#define ERR_UNKNOWN_CODE_FPGA 'c'
// Envoie les infos de debug
#define A2CI_DBG 'D'
struct __attribute__ ((packed)) A2CI_DBGs {
struct position actuel;
struct position destination;
unsigned char movement;
struct F2AI_CODERs deltaCoder;
uint16_t nbCalcPos;
// ...
};
#endif

View file

@ -1,99 +0,0 @@
#include "AF.h"
#include "AC.h"
void registerRxHandlerAF(unsigned char code, rxHandler handler)
{
rxHandlersAF[code] = handler;
}
ISR(USART1_UDRE_vect)
{
// When a transmit is ready to be done again
UDR1 = *toSendAF;
toSendAF++;
toSendSizeAF--;
if (toSendSizeAF <= 0) {
UCSR1B &= ~(1 << UDRIE0);
TaskHandle_t holder = xSemaphoreGetMutexHolder(sSendAF);
if (holder != NULL) {
vTaskNotifyGiveFromISR(holder, NULL);
}
}
}
void sendAF(unsigned char code, void* data, size_t size)
{
xSemaphoreTake(sSendAF, portMAX_DELAY);
toSendAF = &code;
toSendSizeAF = sizeof(code);
UCSR1B |= (1 << UDRIE0);
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
if (size > 0) {
toSendAF = data;
toSendSizeAF = size;
UCSR1B |= (1 << UDRIE0);
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
}
xSemaphoreGive(sSendAF);
}
ISR(USART1_RX_vect)
{
// When a character is received
vTaskNotifyGiveFromISR(tReaderAF, NULL);
}
unsigned char readByteAF()
{
while (!bit_is_set(UCSR1A, RXC1)) {
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
}
return UDR1;
}
void readAF(void* data, size_t size)
{
unsigned char* p = data;
for (int i = 0; i < size; i++) {
*p = readByteAF();
p++;
}
}
void TaskReaderAF(void* pvParameters)
{
(void)pvParameters;
unsigned char code;
for (;;) {
code = readByteAF();
rxHandler handler = rxHandlersAF[code];
if (handler != NULL) {
handler();
} else {
struct A2CD_ERRs err = { ERR_UNKNOWN_CODE_FPGA };
sendAC(A2CD_ERR, &err, sizeof(err));
}
}
}
void configureAF()
{
/* Set baud rate */
UBRR1 = AF_PRESCALER;
/* Set off UART baud doubler */
UCSR1A &= ~(1 << U2X1);
/* Enable transmitter & receiver with interrupts */
UCSR1B = (1 << RXCIE1 | 1 << TXEN1 | 1 << RXEN1);
/* Set 8 bits character and 1 stop bit */
UCSR1C = (1 << UCSZ11 | 1 << UCSZ10);
for (int i = 0; i < 256; i++) {
rxHandlersAF[i] = NULL;
}
sSendAF = xSemaphoreCreateMutex();
xTaskCreate(TaskReaderAF, "TaskReaderAF", 128, NULL, 2, &tReaderAF);
}

View file

@ -1,35 +0,0 @@
/*
* Définition des fonctions utilisées pour échager entre l'Arduino et le chef
*/
#ifndef __AF_H_
#define __AF_H_
#include <FreeRTOS.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <queue.h>
#include <semphr.h>
#include <stdlib.h>
#include <task.h>
#include "AFsignals.h"
#define CPU_FREQ 16000000UL
#define AF_PRESCALER CPU_FREQ / (AF_BAUDRATE << 4) - 1
TaskHandle_t tReaderAF;
SemaphoreHandle_t sSendAF;
unsigned char* toSendAF;
size_t toSendSizeAF;
typedef void (*rxHandler)(void);
rxHandler rxHandlersAF[256];
void registerRxHandlerAF(unsigned char code, rxHandler handler); // À utiliser après configureAF();
void sendAF(unsigned char code, void* data, size_t size);
unsigned char readByteAF(); // À utiliser uniquement depuis un rxHandler
void readAF(void* data, size_t size); // À utiliser uniquement depuis un rxHandler
void TaskReaderAF(void* pvParameters); // Privé
void configureAF();
#endif

View file

@ -1,64 +0,0 @@
/*
* Définition des signaux échagés entre l'Arduino et le chef
*/
#ifndef __AFSIGNALS_H_
#define __AFSIGNALS_H_
#include <stdint.h>
#define AF_BAUDRATE 9600UL
// Structures used everywhere
// D: Direct
// Sens naturel : Envoi de donnée
// Sens inverse : Accusé de réception
// I: Indirect
// Sens inverse : Demande de donnée
// Sens naturel : Envoi de donnée
// T: Trigger
// Sens inverse : Paramètrage du trigger
// Sens naturel : Envoi de trigger
// Arduino → FPGA
// Pour le debug
#define A2FD_PING 'P'
// FPGA → Arduino
// Erreur quelconque
#define F2AD_ERR 'E'
struct __attribute__ ((packed)) F2AD_ERRs {
unsigned char code;
};
#define ERR_UNKNOWN_CODE 'C'
// Récupère les valeur des encodeurs
#define F2AI_CODER 'D'
struct __attribute__ ((packed)) F2AI_CODERs {
int16_t dL;
int16_t dR;
};
// Récupère les valeur des capteurs de distance
#define F2AI_CAPT 'C'
struct __attribute__ ((packed)) F2AI_CAPTs {
uint16_t front;
uint16_t back;
};
// Récupère les valeur des capteurs de distance (trigger au supérieur)
#define F2AT_CAPT 'c'
// /!\ Structure de la requête de trigger (A→F). Les données seront envoyées avec F2AI_CAPT
struct __attribute__ ((packed)) F2AT_CAPTs {
uint16_t front;
uint16_t back;
};
#endif

4
arduino/Arduino-Makefile/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
*.o
build-cli
/.project
build-*

View file

@ -0,0 +1,5 @@
language: c
compiler:
- gcc
script: tests/script/runtests.sh
before_install: tests/script/bootstrap.sh

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,36 @@
# Contributing To Arduino Makefile
Community made patches, localizations, bug reports, documentation and contributions are always welcome and are crucial to the success of this project.
When contributing please ensure you follow the guidelines below so that we can keep on top of things.
## Getting Started
Submit a ticket for your issue, assuming one does not already exist.
- Raise it on our [Issue Tracker](https://github.com/sudar/Arduino-Makefile/issues)
- Clearly describe the issue including steps to reproduce the bug.
- Make sure you fill in the earliest version that you know has the issue as well as the following
- Your operating system (Mac, Linux/Unix, Windows)
- Your Arduino IDE version
- Snippet of your makefile
## Making Changes
- Fork the repository on GitHub
- Make the changes to your forked repository
- Update the [changelog file](HISTORY.md) and add a note about your change. If possible prefix it with either Fix, Tweak or New
- If you are adding or changing the behavior of any variable, then update the corresponding documentation in the [arduino-mk-vars.md](arduino-mk-vars.md) file as well
- When committing, reference your issue (if present) and include a note about the fix
- If possible (and if makes sense) do atomic commits
- Try to follow [this guideline](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) while choosing the git commit message
- If it makes sense then add a unit test case for the changes that you are making
- Push the changes to your fork and submit a pull request to the 'master' branch of the this repository
At this point you're waiting on us to merge your pull request. We'll review all pull requests, and make suggestions and changes if necessary.
# Additional Resources
- [General GitHub Documentation](http://help.github.com/)
- [GitHub Pull Request documentation](http://help.github.com/send-pull-requests/)
- [Guide about contributing code in GitHub](http://sudarmuthu.com/blog/contributing-to-project-hosted-in-github)

View file

@ -0,0 +1,87 @@
# Useful functions
# Returns the first argument (typically a directory), if the file or directory
# named by concatenating the first and optionally second argument
# (directory and optional filename) exists
dir_if_exists = $(if $(wildcard $(1)$(2)),$(1))
# Run a shell script if it exists. Stops make on error.
runscript_if_exists = \
$(if $(wildcard $(1)), \
$(if $(findstring 0, \
$(lastword $(shell $(abspath $(wildcard $(1))); echo $$?))), \
$(info Info: $(1) success), \
$(error ERROR: $(1) failed)))
# For message printing: pad the right side of the first argument with spaces to
# the number of bytes indicated by the second argument.
space_pad_to = $(shell echo $(1) " " | head -c$(2))
# Call with some text, and a prefix tag if desired (like [AUTODETECTED]),
show_config_info = $(call arduino_output,- $(call space_pad_to,$(2),20) $(1))
# Call with the name of the variable, a prefix tag if desired (like [AUTODETECTED]),
# and an explanation if desired (like (found in $$PATH)
show_config_variable = $(call show_config_info,$(1) = $($(1)) $(3),$(2))
# Just a nice simple visual separator
show_separator = $(call arduino_output,-------------------------)
$(call show_separator)
$(call arduino_output,Arduino.mk Configuration:)
########################################################################
#
# Detect OS
ifeq ($(OS),Windows_NT)
CURRENT_OS = WINDOWS
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CURRENT_OS = LINUX
endif
ifeq ($(UNAME_S),Darwin)
CURRENT_OS = MAC
endif
endif
$(call show_config_variable,CURRENT_OS,[AUTODETECTED])
########################################################################
#
# Travis-CI
ifneq ($(TEST),)
DEPENDENCIES_DIR = /var/tmp/Arduino-Makefile-testing-dependencies
DEPENDENCIES_MPIDE_DIR = $(DEPENDENCIES_DIR)/mpide-0023-linux64-20130817-test
ifeq ($(MPIDE_DIR),)
MPIDE_DIR = $(DEPENDENCIES_MPIDE_DIR)
endif
DEPENDENCIES_ARDUINO_DIR = $(DEPENDENCIES_DIR)/arduino-1.0.6
ifeq ($(ARDUINO_DIR),)
ARDUINO_DIR = $(DEPENDENCIES_ARDUINO_DIR)
endif
endif
########################################################################
# Arduino Directory
ifndef ARDUINO_DIR
AUTO_ARDUINO_DIR := $(firstword \
$(call dir_if_exists,/usr/share/arduino) \
$(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) \
$(call dir_if_exists,/Applications/Arduino.app/Contents/Java) )
ifdef AUTO_ARDUINO_DIR
ARDUINO_DIR = $(AUTO_ARDUINO_DIR)
$(call show_config_variable,ARDUINO_DIR,[AUTODETECTED])
else
echo $(error "ARDUINO_DIR is not defined")
endif
else
$(call show_config_variable,ARDUINO_DIR,[USER])
endif
ifeq ($(CURRENT_OS),WINDOWS)
ifneq ($(shell echo $(ARDUINO_DIR) | egrep '^(/|[a-zA-Z]:\\)'),)
echo $(error On Windows, ARDUINO_DIR must be a relative path)
endif
endif

View file

@ -0,0 +1,323 @@
A Makefile for Arduino Sketches
===============================
The following is the rough list of changes that went into different versions.
I tried to give credit whenever possible. If I have missed anyone, kindly add it to the list.
### In Development
- Fix: Do not include the Arduino header when calling generate_assembly on .cpp files. (https://github.com/Batchyx)
- Fix: Auto-detect F_CPU on Teensy from boards.txt (https://github.com/DaWelter)
- Fix: params typo in PuTTY section (issue #487) (https://github.com/ericdand)
- Fix: Fixed sed expression to properly format show_submenu (issue #488) (https://github.com/cbosdo)
- New: Add support for good old cu as monitor command (issue #492) (https://github.com/mwm)
### 1.5.2 (2017-01-11)
- New: Add LTO support for users with avr-gcc > 4.9 (issue #446 & #456) (https://github.com/sej7278)
- Tweak: Updated Linux instructions and sync documentation from the old blog(), README.md and Arduino.mk (https://github.com/az-z)
- Tweak: Documentation for Windows updated to include installation of PySerial (https://github.com/sovcik)
- Fix: Updated CXXFLAGS_STD to match upstream 1.6 (issue #424) (https://github.com/calvinli)
- Fix: Added support for attiny core's use of chip instead of cpu in submenus (https://github.com/straccio)
- Fix: ARDUINO_VERSION can cope with the longer 1.6.10 version string (issue #444) (https://github.com/sej7278)
- Fix: Changed PARSE_BOARD to handle colons in e.g. CORE or VARIANT (issue #461) (https://github.com/sej7278)
- Fix: Changed Teensy.mk to support Arduino 1.6.12 and Teensyduino 1.30 (issues #383 , #431) (https://github.com/georgeharker)
### 1.5.1 (Debian version: 1.5-3) (2016-02-22)
- New: Add show_submenu target (https://github.com/drewhutchison)
- New: Add AVR Dragon to list of ISP's without a port (https://github.com/mtnocean)
- New: Add more board examples to Blink demo (https://github.com/sej7278)
- New: Add option to split avrdude MCU from avr-gcc MCU (Issue #357) (https://github.com/hhgarnes)
- New: Add support for /dev/tty.wchusbserial* (comes with cheap clones - DCCduino) (https://github.com/biesiad)
- New: Add support for picocom as serial monitor (https://github.com/biesiad)
- Tweak: Add support for Adafruit trinket3/trinket5/protrinket3/protrinket5 by improved BOARDS_TXT parsing (Issue #393) (https://github/com/zabereer)
- Tweak: Looks for submenu items first when parsing BOARDS_TXT (Issue #347) (https://github.com/sej7278)
- Tweak: Various spelling/grammar/typo fixes (https://github.com/dcousens)
- Tweak: Clarified some 1.5+ issues in docs (Issue #352) (https://github.com/sej7278)
- Tweak: Added some more Continuous Integration tests (https://github.com/sej7278)
- Tweak: Updated Fedora instructions (https://github.com/sej7278)
- Fix: Preserve original extension for object files, support asm sources in core, fixes pulseInASM (Issue #255, #364) (https://github.com/sej7278)
- Fix: Make sure TARGET is set correctly when CURDIR contains spaces (https://github.com/svendahlstrand)
- Fix: Ensure AVRDUDE_CONF is set when AVR_TOOLS_DIR is, not just on Windows (Issue #381) (https://github.com/sej7278)
- Fix: Rename VENDOR to ARDMK_VENDOR to workaround tcsh issue (Issue #386) (https://github.com/sej7278)
- Fix: Document OSX 1.0/1.6 ARDUINO_DIR differences (https://github.com/thomaskilian)
- Fix: Fix regex to support BOARD_TAGs with hyphens e.g. attiny44-20 (https://github.com/sej7278)
- Fix: Remove check for BOOTLOADER_PATH, just check for BOOTLOADER_FILE (Issue #402) (https://github.com/sej7278)
- Fix: Port ard-reset-arduino to pyserial 3.0 (#407, #408) (https://github.com/gauteh)
### 1.5 (2015-04-07)
- New: Add support for new 1.5.x library layout (Issue #275) (https://github.com/lukasz-e)
- New: Add support for 1.5.x vendor/hardware architecture library location (Issue #276) (https://github.com/lukasz-e)
- New: Added test suite and integration with travis CI. (https://github.com/peplin)
- New: Add information about `Bare-ArduinoProject` in README. (https://github.com/ladislas)
- New: Add information about reporting bugs to the correct project (Issue #231). (https://github.com/sej7278)
- New: Add documentation about CFLAGS_STD and CXXFLAGS_STD (Issue #234) (https://github.com/ladislas)
- New: Allow "make clean" target to be extended (Issue #239). (https://github.com/sej7278)
- New: Add makefile and gcc version info to config output. (https://github.com/sej7278)
- New: Support for Teensy 3.x (https://github.com/stepcut)
- New: Support for PuTTY under Windows (https://github.com/PeterMosmans)
- New: Add support for installation using homebrew(https://github.com/ladislas)
- New: Add support and example for flashing on a remote RPi. (https://github.com/Gaboose)
- Tweak: Update Makefile-example.mk with STD flags (https://github.com/ladislas)
- Tweak: Allow remove of any OBJDIR with `$(REMOVE) $(OBJDIR)`. (https://github.com/ladislas)
- Tweak: Add cpp to extensions supported by "make generate_assembly". (https://github.com/sej7278)
- Tweak: Update travis-ci to test against Arduino 1.0.6. (https://github.com/sej7278)
- Tweak: Updated package instructions for Arch/Fedora/Raspbian. (https://github.com/sej7278)
- Tweak: Remove $(EXTRA_XXX) variables (Issue #234) (https://github.com/ladislas)
- Tweak: Moved location of avrdude for 1.5.8 on Linux (Issue #301) (https://github.com/sej7278)
- Tweak: Allow 'build.core' param as found in [arduino-tiny](https://code.google.com/p/arduino-tiny/) Prospective Boards.txt. (https://github.com/Gaboose)
- Tweak: Replace CXX_NAME with CXX as per the Emacs Flymake Wiki (Issue #309) (https://github.com/sej7278)
- Tweak: Ability to override `USB_TYPE` in Teensy.md (Issue #313) (https://github.com/Poofjunior)
- Tweak: Integration instructions for CodeBlocks IDE (Issue #321) (https://github.com/fbielejec)
- Tweak: Add BOARD_SUB to OBJDIR if defined in 1.5+ (https://github.com/sej7278)
- Tweak: Add = to PARSE_BOARD regex to make it less greedy and not match vid.0, vid.1 and vid (https://github.com/sej7278)
- Tweak: Added note about clock submenu's being used as F_CPU (https://github.com/sej7278)
- Tweak: Better autodetection of ARDUINO_SKETCHBOOK and ARDUINO_DIR on OSX (https://github.com/sej7278)
- Fix: Improved Windows (Cygwin/MSYS) support (https://github.com/PeterMosmans)
- Fix: Change "tinyladi" username to "ladislas" in HISTORY.md. (https://github.com/ladislas)
- Fix: Make avr-g++ use CXXFLAGS instead of CFLAGS. (https://github.com/sej7278)
- Fix: Allow the use of CFLAGS_STD and CXXFLAGS_STD and set defaults (Issue #234) (https://github.com/ladislas)
- Fix: Update "make show_boards" regex to work with the Due in 1.5. (https://github.com/sej7278)
- Fix: Allow user libaries/sketches to have the same name as system libs. (Issue #244, #229). (https://github.com/sej7278)
- Fix: Remove impact of travis-ci from regular users. (Issue #258). (https://github.com/sej7278)
- Fix: objcopy quoting issue on Windows. (Issue #272). (https://github.com/sej7278)
- Fix: Add "avrispmkii" to the list of isp that don't have a port. (Issue #279). (https://github.com/sej7278)
- Fix: Make CXX compile .cpp files instead of CC. (Issue #285). (https://github.com/sej7278)
- Fix: Changed IDE download URL *again* for Travis-CI. (https://github.com/sej7278)
- Fix: Allow avrdude to erase the chip before programming during ispload (https://github.com/tchebb)
- Fix: Fix speed regression. Thanks ladislas (Issue #280) (https://github.com/sej7278)
- Fix: Removed some double quotes that were breaking variable expansion. (https://github.com/sej7278)
- Fix: Fixed PLATFORM_LIB support for 1.5+ and removed duplicate libs (https://github.com/sej7278)
- Fix: Added ARCHITECTURE to ALTERNATE_CORE_PATH to support 1.5+ cores like arduino-tiny (https://github.com/sej7278)
- Fix: Can now find IDE 1.5+ preferences.txt on Linux and Mac (https://github.com/sej7278)
- Fix: Added support for VARIANT being a submenu item in 1.6 cores like attiny (https://github.com/sej7278)
- Fix: Replaced copyright symbol causing sed problems on OSX (Issue #335). (https://github.com/sej7278)
- Fix: Fix issues with resetting Leonardo and Micro boards(Issue #340) (https://github.com/calvinli)
### 1.3.4 (2014-07-12)
- Tweak: Allow spaces in "Serial.begin (....)". (Issue #190) (https://github.com/pdav)
- Add: Add support for compiling assembler code. (Issue #195) (https://github.com/hrobeers)
- Add: Try to guess port from wildcards if not specified. (Issue #197) (https://github.com/tuzz)
- Fix: Check that on windows ARDUINO_DIR (and MPIDE_DIR) is a relative path. (Issue #201 and #202) (https://github.com/sej7278)
- Add: List board name as well as tag in `make show_boards`. (Issue #204) (https://github.com/sej7278)
- Fix: Add missing newlines at end of some echo's (Issue #207) (https://github.com/sej7278)
- Fix: Add missing/reorder/reword targets in `make help` (https://github.com/sej7278)
- New: Arduino.mk is now compatible with Flymake mode (https://github.com/rbarzic)
- Fix: MONITOR_PORT detection (Issue #213, #215) (https://github.com/sej7278)
- Tweak: Audited regexes/quoting/wildcards (Issue #192) (https://github.com/sej7278)
- New: Build core objects in subdirectory (Issue #82) (https://github.com/sej7278)
### 1.3.3 (2014-04-12)
- Fix: Make a new manpage for ard-reset-arduino. Fixes issue #188 (https://github.com/sej7278)
### 1.3.2 (2014-04-11)
- Fix: Add arduino-mk-vars.md file to RPM SPECfile. (https://github.com/sej7278)
- Fix: Add avr-libc/malloc.c and realloc.c to included core files. Fixes issue #163 (https://github.com/sej7278)
- Fix: Add "gpio" to the list of isp that don't have a port. (Issue #165, #166) (https://github.com/sej7278)
- Fix: Add "-D__PROG_TYPES_COMPAT__" to the avr-g++ compiler flags to match IDE. (https://github.com/sej7278)
- New: Create `Makefile-example-mk`, a *real life* `Makefile` example, to be used as a reference. (https://github.com/ladislas)
- Tweak: Add `OBJDIR` to `arduino-mk-vars.md` (https://github.com/ladislas)
- Tweak: *Beautify* `arduino-mk-vars.md` with code blocks. (https://github.com/ladislas)
- Fix: AVR tools paths for chipKIT in Linux. (https://github.com/peplin)
- Fix: Consider usb or usb:... to be a valid ISP_PORT (https://github.com/geoffholden)
- Add: Add phony target to run pre-build hook script (https://github.com/jrid)
- Fix: Add BOOTLOADER_PARENT to `arduino-mk-vars.md` and fixed BOOTLOADER_PATH example. (https://github.com/sej7278)
- Tweak: Replace perl reset script with Python script. (https://github.com/sej7278)
- Tweak: Made choice of Python2/3 interpreter up to the OS. (https://github.com/peplin)
- Tweak: Simplified packaging dependencies. (https://github.com/sej7278)
- Tweak: Tweak AVRDUDE conf detection in windows. (https://github.com/EAGMnor)
### 1.3.1 (2014-02-04)
- Fix: BUNDLED_AVR_TOOLS_DIR is now set properly when using only arduino-core and not the whole arduino package. (https://github.com/sej7278)
- New: Document all variables that can be overridden. (https://github.com/sej7278)
- New: Add a new `help_vars` target to display information about variables that can be overridden.
### 1.3.0 (2014-01-29)
- Fix: Use more reliable serial device naming in Windows. Fix issue #139 and #155 (https://github.com/peplin)
- Fix: Document that ARDUINO_DIR must be a relative path in Windows. Fix issue #156 (https://github.com/peplin)
- Tweak: Don't hard code MONITOR_PORT in examples, for more flexible testing. (Issue #157) (https://github.com/peplin)
- Tweak: Silence the stderr output from call to `which`. (Issue #158) (https://github.com/peplin)
- Fix: Override complete compiler tool paths for chipKIT. (Issue #159) (https://github.com/peplin)
- New: The makefile is compatible with Windows
- New: Update `README.md` file about usage and Windows compatibility
### 1.2.0 (2014-01-14)
- Add: Add RPM SPECfile and new `package` directory to store package instructions and files (https://github.com/sej7278)
- Fix: Remove use of arduino-mk subdirectory in git. Fix issue #151, #152 and #147 (https://github.com/sej7278)
- Fix: Remove `arduino-mk` directory from all examples. Fix #154
### 1.1.0 (2013-12-26)
- Don't append port details to avrdude for usbasp. See #123
- Ignore commented lines while parsing boards.txt file. See #124
- In ISP mode, read baudrate and programmer from boards.txt. See #125
- Add `burn_bootloader` target. See #85
- Show correct path to `arduino.mk` file in help message. Fix #120
- Change echo for printf. Fix #129 (https://github.com/thomassigurdsen)
- Add support for ChipKiT 2013. Fix #136 (https://github.com/peplin)
- Auto detect and include libraries specified in `USER_LIB_PATH`. Fix #135 (https://github.com/ladislas)
- Use `MAKEFILE_LIST` to get the name of the make file. Fix #130 (https://github.com/cantora)
- New: Add option to set fuses without burning a bootloader. Fix #141 (https://github.com/sej7278)
- Tweak: Don't append port details to avrdude for usbtiny. Fix #140 and #138 (https://github.com/PPvG)
- Fix: Handle relative paths of bootloader file while burning bootloaders. Fix #126 and #142 (https://github.com/sej7278)
- New: Add `CONTRIBUTING.md` explaining how to contribute to the project.
- New: Force -Os optimization for SoftwareSerial. Add `OPTIMIZATION_FLAGS` and `DEBUG_FLAGS`. (https://github.com/mahoy)
- Fix: Use `ARDUINO_HEADER` variable instead of hardcoded file names. Fix #131
### 1.0.1 (2013-09-25)
- Unconditionally add -D in avrdude options. See #114
### 1.0.0 (2013-09-22)
- Add $OBJDIR to the list of configuration that gets printed. Fix issue #77
- Add support for specifying optimization level. Fix issue #81
- Add support for reseting "Micro" Arduino. Fix issue #80 (https://github.com/sej7278)
- Remove "utility" from example makefiles. Fix issue #84
- Auto detect alternate core path from sketchbook folder. Fix issue #86
- Remove redundant checks for ARDUINO_DIR
- Improve avrdude and avrdude.conf path auto detection. Fix issue #48
- Move binary sketch size verification logic inside makefile. Fix issue #54
- Remove dependency on wait-connection-leonardo shell script. Fix issue #95
- Add support for the Digilent chipKIT platform. (https://github.com/peplin)
- Implement ard-parse-boards with shell scripting instead of Perl (https://github.com/peplin)
- Compile with debugging symbols only when DEBUG=1 (https://github.com/peplin)
- Replace Leonardo detection with Caterina detection (https://github.com/sej7278)
- Autodetect baudrate only if either a .ino/.pde is present
- Allow building with Arduino core, without a .ino/.pde file
- Ability to support different Arduino cores (https://github.com/sej7278)
### 0.12.0 (2013-06-20)
- Fix "generated_assembly" target, which got broken earlier. Fix issue #76 (https://github.com/matthijskooijman)
- Deprecate "generated_assembly" target in favour of "generate_assembly". Fix issue #79
### 0.11.0 (2013-06-15)
- Replace hardcoded executables with variable
- Fix whitespace issues
- Add a warning when HEX_MAXIMUM_SIZE is not specified
- Add the ability to configure avrdude options. Fix issue #53
- Handle cases where certain fuse bits are not present. Fix issue #61
- Add support for compiling plain AVR C files. Fix issue #63
- Add an example to show how to compile AVR C files. Fix issue #73
### 0.10.6 (2013-06-14)
- Fix whitespace and add /dev/null redirection (https://github.com/sej7278)
- Change the way AUTO_ARDUINO_VERSION is computed (https://github.com/sej7278)
- Make serial monitor baudrate detection work in Mac as well(https://github.com/sej7278)
- Fix directory creation for library source files (https://github.com/matthijskooijman)
- Rewrite ard-leonardo-reset script in perl (https://github.com/sej7278)
### 0.10.5 (2013-06-11)
- Add USB_VID and USB_PID to CPPFLAGS only if the board is Leonardo.
- Allow adding extra common dependencies (COMMON_DEPS) (https://github.com/gaftech)
- Added ifndef ARDUINO_VAR_PATH for compiling for the attiny (https://github.com/danielesteban)
- Strip extra whitespace from the `BOARD_TAG` variable
- Enhanced support for programming using Arduino as ISP
- Added example to show how to program using Arduino as ISP
- Add support for Leonardo boards. Took code from (https://github.com/guicho271828)
### 0.10.4 (2013-05-31) @matthijskooijman
- Improved BAUD_RATE detection logic
- Added logic to check if there is only .ino or .pde file
- Compile .ino/.pde files directly
- Output configuration only once
- Try to read Version.txt file only if it is present
- Refactored dependency code
### 0.10.3 16.xii 2012 gaftech
- Enabling creation of EEPROM file (.eep)
- EEPROM upload: eeprom and raw_eeprom targets
- Auto EEPROM upload with isp mode: ISP_EEPROM option.
- Allow custom OBJDIR
### 0.10.2 15.xii.2012 Sudar
- Added sketch size verification. (https://github.com/fornellas)
- Show original line number for error messages (https://github.com/WizenedEE)
- Removed -w from CPPFLAGS to show warnings (https://github.com/gaftech)
- Changed shebang to use /usr/bin/env (https://github.com/anm)
- set USB_VID and USB_PID only for leonardo boards(https://github.com/alohr)
- Updated Readme (https://github.com/fr0sty1/)
### 0.10.1 15.xii.2012 Sudar
- Merged all changes from Upstream and the following changes from https://github.com/rpavlik
- Allow passing extra flags
- Make listing files more useful
- Add knowledge of device-specific assembler
- Use variables instead of hardcoded commands
- Make disasm more helpful
- Change .sym output
- Provide symbol_sizes and generated_assembly targets.
- Be able to silence configuration output
- Make everybody depend on the makefile, in case cflags are changed, etc.
- Make the makefile error if the arduino port is not present.
### 0.10 17.ix.12 M J Oldfield
- Added installation notes for Fedora (ex Rickard Lindberg).
- Changed size target so that it looks at the ELF object,
not the hexfile (ex Jared Szechy and Scott Howard).
- Fixed ARDUNIO typo in README.md (ex Kalin Kozhuharov).
- Tweaked OBJDIR handling (ex Matthias Urlichs and Scott Howard).
- Changed the name of the Debian/Ubuntu package (ex
Scott Howard).
- Only set AVRDUDE_CONF if it's not set (ex Tom Hall).
- Added support for USB_PID/VID used by the Leonardo (ex Dan
Villiom Podlaski Christiansen and Marc Plano-Lesay).
### 0.9.3.2 10.ix.2012 Sudar
- Fixed a typo in README. Issue reported at upstream (https://github.com/mjoldfield/Arduino-Makefile/issues/21)
### 0.9.3.1 18.viii.2012 jeffkowalski
- Autodetect ARDUINO_LIBS from includes in LOCAL_SRCS
- Autodetect ARDUINO_SKETCHBOOK from file set by Arduino IDE
- Autodetect ARDMK_DIR based on location of this file
- Added support for utility directory within SYS and USER libraries
### 0.9.3 13.vi.2012
- Auto detect ARDUINO_DIR, Arduino version (https://github.com/rpavlik/)
- Categorize libs into user and system (https://github.com/rpavlik/)
- Dump size at the end of the build (https://github.com/rpavlik/)
- Lots and lots of improvements (https://github.com/rpavlik/)
- Changed bytes option for the head shell command, so that it works in Mac as well
- Auto detect Serial Baud rate from sketch if possible
### 0.9.2 06.vi.2012
- Allow user to choose source files (LOCAL_*_SRCS flags) (https://github.com/Gaftech)
- Modified "make size" behavior: using --mcu option and targeting .elf file instead of .hex file.(https://github.com/Gaftech)
### 0.9.1 06.vi.2012
- Corrected the ubuntu package names
- Prevent the *file-not-found* error if the depends.mk file is not needed
- Delete the build-cli folder as well while doing make clean
- Added support for compiling .pde files in Arduino 1.0 environment
- Replaced = with += in CPPFLAGS assignment so that we can set CPPFLAGS per sketch if needed
- Changed AVRDUDE_CONF so it can be defined in per-project makefile (https://github.com/WizenedEE)
- Cleaner way to delete the build-cli directory when make clean is invoked
- The package name in Debian and Ubuntu is arduino-mk (https://github.com/maqifrnswa)
### 2012-02-12, version 0.8
- Patches for version 1.0 of the Arduino IDE. Older versions might still work, but Ive not tested it.
- A change to the build process: rather than link all the system objects directly into the executable, bundle them in a library first. This should make the final executable smaller.
- If TARGET isnt explicitly set, default to the current directory name. Thanks to Daniele Vergini for this patch.
- Add support for .c files in system libraries: Dirk-Willem van Gulik and Evan Goldenberg both reported this and provided patches in the same spirit.
- Added a size target as suggested by Alex Satrapa.
### Unreleased, version 0.7
- Added -lm to the linker options, and -F to stty.
### 2011-06-23, version 0.6
- Added ard-parse-boards. Mark Sproul suggested doing something like this ages ago, but Ive only recently looked at it in detail.
- Fabien Le Lez reported that one needs to link with -lc to avoid [linker errors](http://forum.arduino.cc/index.php/topic,40215.0.html).
### 2011-06-23, version 0.5
- Imported changes from Debian/Ubuntu, which incorporate a patch from Stefan Tomanek so that libraries would be compiled too.
Note: Many other people sent me similar patches, but I didn't get around to using them. In the end, I took the patch from Debian and Ubuntu: there seems merit in not forking the code and using a tested version. So, thanks and apologies to Nick Andrew, Leandro Coletto Biazon, Thibaud Chupin, Craig Hollabaugh, Johannes H. Jensen, Fabien Le Lez, Craig Leres, and Mark Sproul.
### 2010-05-24, version 0.4
Tweaked rules for the reset target on Philip Hands advice.
### 2010-05-21, version 0.3
- Tidied up the licensing, making it clear that its released under LGPL 2.1.
- [Philip Hands](http://hands.com/~phil/) sent me some code to reset the Arduino by dropping DTR for 100ms, and I added it.
- Tweaked the Makefile to handle version 0018 of the Arduino software which now includes main.cpp. Accordingly we dont need to—and indeed must not—add main.cxx to the .pde sketch file. The paths seem to have changed a bit too.

View file

@ -0,0 +1,415 @@
# A Makefile for Arduino Sketches [![Build Status](https://travis-ci.org/sudar/Arduino-Makefile.svg)](https://travis-ci.org/sudar/Arduino-Makefile)
This is a very simple Makefile which knows how to build Arduino sketches. It defines entire workflows for compiling code, flashing it to Arduino and even communicating through Serial monitor. You don't need to change anything in the Arduino sketches.
## Features
- Very robust
- Highly customizable
- Supports all official AVR-based Arduino boards
- Supports chipKIT
- Supports Teensy 3.x (via Teensyduino)
- Works on all three major OS (Mac, Linux, Windows)
- Auto detects serial baud rate and libraries used
- Support for `*.ino` and `*.pde` sketches as well as raw `*.c` and `*.cpp`
- Support for Arduino Software versions 0.x, 1.0.x, 1.5.x and 1.6.x except 1.6.2.
We recommend 1.6.3 or above version of Arduino IDE.
- Automatic dependency tracking. Referred libraries are automatically included
in the build process. Changes in `*.h` files lead to recompilation of sources which include them
## Installation
### Through package
#### Using apt-get (or aptitude)
If you're using FreeBSD, Debian, Raspbian or Ubuntu, you can find this in the `arduino-mk`
package which can be installed using `apt-get` or `aptitude`.
```sh
sudo apt-get install arduino-mk
```
#### homebrew (or linuxbrew)
If you're using homebrew (or [linuxbrew](https://github.com/Homebrew/linuxbrew)) then you can find this in the
`arduino-mk` package which can be installed using the following commands.
Also make sure you have the necessary dependencies installed. Refer to the [Requirements](#requirements) section below to install the dependencies.
```sh
# add tap
$ brew tap sudar/arduino-mk
# to install the last stable release
$ brew install arduino-mk
# to install the development version
$ brew install --HEAD arduino-mk
```
#### Arch Linux
Arch Linux users can use the unofficial AUR package [arduino-mk](https://aur.archlinux.org/packages/arduino-mk/).
It can be installed using the following command.
```sh
yaourt -S arduino-mk
```
#### Fedora
Fedora Linux users can use our packaging instructions [here](https://github.com/sudar/Arduino-Makefile/tree/master/packaging/fedora)
to build an RPM.
### From source
- Download the latest release
- Or clone it from Github using the command `git clone git@github.com:sudar/Arduino-Makefile.git`
- Check the [usage section](https://github.com/sudar/Arduino-Makefile#usage) in this readme about setting usage options
## Requirements
### Arduino IDE
You need to have the Arduino IDE. You can either install it through the
installer or download the distribution zip file and extract it.
### pySerial
The Makefile also delegates resetting the board to a short Python program.
You'll need to install [`pySerial`](https://pypi.python.org/pypi/pyserial) to use it though.
On most systems you should be able to install it using either `pip` or `easy_install`.
```sh
pip install pyserial
# or if you prefer easy_install
easy_install -U pyserial
```
If you prefer to install it as a package, then you can do that as well.
On Debian or Ubuntu:
```sh
apt-get install python-serial
```
On Fedora:
```sh
yum install pyserial
# or on Fedora 22+
dnf install pyserial
```
On openSUSE:
```sh
zypper install python-serial
```
On Mac using MacPorts:
```sh
sudo port install py27-serial
```
On Windows:
You need to install Cygwin and its packages for Make, Perl and the following Serial library.
Assuming you included Python in your Cygwin installation:
1. download PySerial source package from [https://pypi.python.org/pypi/pyserial](https://pypi.python.org/pypi/pyserial)
2. extract downloaded package running
```tar xvzf dowloaded_package_name.tar.gz```
3. navigate to extracted package folder
4. build and install Python module:
```
python setup.py build
python setup.py install
```
## Usage
Download a copy of this repo somewhere to your system or install it through a package by following the above installation instruction.
Sample makefiles are provided in the `examples/` directory. E.g. [Makefile-example](examples/MakefileExample/Makefile-example.mk) demonstrates some of the more advanced options,
whilst [Blink](examples/Blink/Makefile) demonstrates the minimal settings required for various boards like the Uno, Nano, Mega, Teensy, ATtiny etc.
MAC:
On the Mac with IDE 1.0 you might want to set:
```make
ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
ARDMK_DIR = /usr/local
AVR_TOOLS_DIR = /usr
MONITOR_PORT = /dev/ttyACM0
BOARD_TAG = mega2560
```
On the Mac with IDE 1.5+ it's like above but with
```
ARDUINO_DIR = /Applications/Arduino.app/Contents/Java
```
LINUX:
You can either declare following variables in your project's makefile or set them as environmental variables.
ARDUINO_DIR Directory where Arduino is installed
ARDMK_DIR Directory where you have copied the makefile
AVR_TOOLS_DIR Directory where avr tools are installed
Keep in mind, that Arduino 1.5.x+ comes with it's own copy of avr tools which you can leverage in your build process here.
Example of ~/.bashrc file:
export ARDUINO_DIR=/home/sudar/apps/arduino-1.0.5
export ARDMK_DIR=/home/sudar/Dropbox/code/Arduino-Makefile
export AVR_TOOLS_DIR=/usr/include
Example of the project's make file:
```make
BOARD_TAG = mega2560
MONITOR_PORT = /dev/ttyACM0
```
WINDOWS:
On Windows (using cygwin), you might want to set:
```make
ARDUINO_DIR = ../../arduino
ARDMK_DIR = path/to/mkfile
MONITOR_PORT = com3
BOARD_TAG = mega2560
```
On Windows (using MSYS and PuTTY), you might want to set the following extra parameters:
```make
MONITOR_CMD = putty
MONITOR_PARMS = 8,1,n,N
```
On Arduino 1.5+ installs, you should set the architecture to either `avr` or `sam` and if using a submenu CPU type, then also set that:
```make
ARCHITECTURE = avr
BOARD_TAG = atmegang
BOARD_SUB = atmega168
```
It is recommended in Windows that you create a symbolic link to avoid problems with file naming conventions on Windows. For example, if your your Arduino directory is in:
c:\Program Files (x86)\Arduino
You will get problems with the special characters on the directory name. More details about this can be found in [issue #94](https://github.com/sudar/Arduino-Makefile/issues/94)
To create a symbolic link, you can use the command “mklink” on Windows, e.g.
```sh
mklink /d c:\Arduino c:\Program Files (x86)\Arduino
```
After which, the variables should be:
```make
ARDUINO_DIR=../../../../../Arduino
```
Instead of:
```make
ARDUINO_DIR=../../../../../Program\ Files\ \(x86\)/Arduino
```
Usefull Variables:
The list of all variables that can be overridden is available at [arduino-mk-vars.md](arduino-mk-vars.md) file.
- `BOARD_TAG` - Type of board, for a list see boards.txt or `make show_boards`
- `MONITOR_PORT` - The port where your Arduino is plugged in, usually `/dev/ttyACM0` or `/dev/ttyUSB0` in Linux or Mac OS X and `com3`, `com4`, etc. in Windows.
- `ARDUINO_DIR` - Path to Arduino installation. In Cygwin in Windows this path must be
relative, not absolute (e.g. "../../arduino" and not "/c/cygwin/Arduino").
- `ARDMK_DIR` - Path where the `*.mk` are present. If you installed the package, then it is usually `/usr/share/arduino`
- `AVR_TOOLS_DIR` - Path where the avr tools chain binaries are present. If you are going to use the binaries that came with Arduino installation, then you don't have to set it. Otherwise set it realtive and not absolute.
## Including Libraries
You can specify space separated list of libraries that are needed for your sketch in the variable `ARDUINO_LIBS`.
```make
ARDUINO_LIBS = Wire SoftwareSerial
```
The libraries will be searched for in the following places in the following order.
- `/libraries` directory inside your sketchbook directory. Sketchbook directory will be auto detected from your Arduino preference file. You can also manually set it through `ARDUINO_SKETCHBOOK`.
- `/libraries` directory inside your Arduino directory, which is read from `ARDUINO_DIR`.
The libraries inside user directories will take precedence over libraries present in Arduino core directory.
The makefile can autodetect the libraries that are included from your sketch and can include them automatically. But it can't detect libraries that are included from other libraries. (see [issue #93](https://github.com/sudar/Arduino-Makefile/issues/93))
## avrdude
To upload compiled files, `avrdude` is used. This Makefile tries to find `avrdude` and it's config (`avrdude.conf`) below `ARDUINO_DIR`. If you like to use the one installed on your system instead of the one which came with Arduino, you can try to set the variables `AVRDUDE` and `AVRDUDE_CONF`. On a typical Linux system these could be set to
```make
AVRDUDE = /usr/bin/avrdude
AVRDUDE_CONF = /etc/avrdude.conf
```
## Teensy 3.x
For Teensy 3.x support you must first install [Teensyduino](http://www.pjrc.com/teensy/teensyduino.html).
See examples/BlinkTeensy for example usage.
## Versioning
The current version of the makefile is `1.5.2`. You can find the full history in the [HISTORY.md](HISTORY.md) file
This project adheres to Semantic [Versioning 2.0](http://semver.org/).
## License
This makefile and the related documentation and examples are 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.
## Contribution
All contributions (even documentation) are welcome :) Open a pull request and I would be happy to merge them.
Also checkout the [contribution guide](CONTRIBUTING.md) for more details.
If you are looking for ideas to work on, then check out the following TODO items or the [issue tracker](https://github.com/sudar/Arduino-Makefile/issues/).
## Limitations / Know Issues / TODO's
- Doesn't support SAM boards yet.
- Since it doesn't do any pre processing like Arduino IDE, you have to declare all methods before you use them ([issue #59](https://github.com/sudar/Arduino-Makefile/issues/59))
- More than one .ino or .pde file is not supported yet ([issue #49](https://github.com/sudar/Arduino-Makefile/issues/49))
- When you compile for the first time, it builds all libs inside Arduino directory even if it is not needed. But while linking only the relevant files are linked. ([issue #29](https://github.com/sudar/Arduino-Makefile/issues/29)). Even Arduino IDE does the same thing though.
- This makefile doesn't support boards or IDE from Arduino.org.
If you find an issue or have an idea for a feature then log them in the [issue tracker](https://github.com/sudar/Arduino-Makefile/issues/)
## Interfacing with other projects/frameworks/IDE's
### Colorgcc
It is possible to use [`colorgcc`](https://github.com/colorgcc/colorgcc) with this makefile. Check out [this comment](http://hardwarefun.com/tutorials/compiling-arduino-sketches-using-makefile#comment-1408) to find usage instructions.
### Emacs/Flymake support
On-the-fly syntax checking in Emacs using the [Flymake](http://www.emacswiki.org/emacs/FlyMake) minor mode is now possible.
First, the flymake mode must be configured to recognize ino files :
Edit the flymake configuration :
```
M-x customize-option RET
flymake-allowed-file-name-masks RET
```
Add the line :
```
("\\.ino\\'" flymake-simple-make-init)
```
Then click on "Apply and Save" button
Then, the following line must be added to the project Makefile :
```make
check-syntax:
$(CXX) -c -include Arduino.h -x c++ $(CXXFLAGS) $(CPPFLAGS) -fsyntax-only $(CHK_SOURCES)
```
### Code:Blocks integration
In Code:Blocks open Project -> Properties -> Project settings tab -> check "This is custom Makefile".
Now go to Settings -> Environment -> Environment variables -> Add
Add three keys with paths as values, using full paths (!):
```make
ARDUINO_DIR=/full/path/to/arduino-1.0.6
ARDMK_DIR=/full/path/to/sketchbook
AVR_TOOLS_DIR=/usr
```
Now to set DEBUG target (this will compile the project) go to Build options -> Debug -> "Make" commands
In Build Project/Target remove $target:
```sh
$make -f $makefile
```
In Clean Project/Target remove $target:
```sh
$make -f $makefile clean
```
To set the RELEASE target (which will compile and upload) go to Build options -> Release -> "Make" commands
In Build Project/Target put:
```sh
$make -f $makefile upload
```
In Clean Project/Target remove $target:
```sh
$make -f $makefile clean
```
## Test Suite
This project includes a suite of example Makefiles and small Arduino and chipKIT
programs to assist the maintainers of the Makefile. Run
`tests/script/bootstrap.sh` to attempt to automatically install the dependencies
(Arduino IDE, MPIDE, etc.). Run `tests/script/runtests.sh` to attempt to compile
all of the examples. The bootstrap script is primarily intended for use by a
continuous integration server, specifically Travis CI. It is not intended for
normal users.
### Bare-ArduinoProject
If you are planning on using this makefile in a larger/professional project, you might want to take a look at the [Bare-ArduinoProject](https://github.com/WeAreLeka/Bare-Arduino-Project) framework.
Similar to HTML frameworks, [Bare-ArduinoProject](https://github.com/WeAreLeka/Bare-Arduino-Project) aims at providing a basic `tree` organization, `Makefile` configurations for both OS X and Linux and a handful of instruction on how to get started with a robust Arduino project architecture.
Further information are available in the [README.md](https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/README.md) as well as in the [use/installation procedure](https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/INSTALL.md).
Please be sure to report issues to [Bare-ArduinoProject](https://github.com/WeAreLeka/Bare-Arduino-Project/issues) if you use it instead of this project.
## Credits
This makefile was originally created by [Martin Oldfield](http://mjo.tc/atelier/2009/02/arduino-cli.html) and he maintained it till v0.10.2.
From May 2013, it is maintained by [Sudar Muthu](http://hardwarefun.com/tutorials/compiling-arduino-sketches-using-makefile) and [Simon John](https://github.com/sej7278) with the help of [40+ contributors](https://github.com/sudar/Arduino-Makefile/graphs/contributors).
## Similar works
- It's not a derivative of this, but Alan Burlison has written a [similar thing](http://bleaklow.com/2010/06/04/a_makefile_for_arduino_sketches.html).
- Alan's Makefile was used in a [Pragmatic Programmer's article](http://pragprog.com/magazines/2011-04/advanced-arduino-hacking).
- Rei Vilo wrote to tell me that he's using the Makefile ina Xcode 4 template called [embedXcode](http://embedxcode.weebly.com/). Apparently it supports many platforms and boards, including AVR-based Arduino, AVR-based Wiring, PIC32-based chipKIT, MSP430-based LaunchPad and ARM3-based Maple.

View file

@ -0,0 +1,213 @@
########################################################################
#
# Support for Teensy 3.x boards
#
# https://www.pjrc.com/teensy/
#
# You must install teensyduino for this Makefile to work:
#
# http://www.pjrc.com/teensy/teensyduino.html
#
# Copyright (C) 2014 Jeremy Shaw <jeremy@n-heptane.com> based on
# work that is copyright Sudar, Nicholas Zambetti, David A. Mellis
# & Hernando Barragan.
#
# This file 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.
#
# Adapted from Arduino 0011 Makefile by M J Oldfield
#
# Original Arduino adaptation by mellis, eighthave, oli.keller
#
# Refer to HISTORY.md file for complete history of changes
#
########################################################################
ifndef ARDMK_DIR
ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
endif
# include Common.mk now we know where it is
include $(ARDMK_DIR)/Common.mk
ARDMK_VENDOR = teensy
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/teensy/avr/cores/teensy3
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/avr/boards.txt
ifndef PARSE_TEENSY
# result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
PARSE_TEENSY = $(shell grep -v "^\#" "$(BOARDS_TXT)" | grep $(1).$(2) | cut -d = -f 2- )
endif
ifndef F_CPU
ifndef BOARD_SUB
SPEEDS := $(call PARSE_TEENSY,"$(BOARD_TAG),menu.speed.*.build.fcpu") # Obtain sequence of supported frequencies.
SPEEDS := $(shell printf "%d\n" $(SPEEDS) | sort -g) # Sort it, just in case. Printf to re-append newlines so that sort works.
F_CPU := $(lastword $(SPEEDS)) # List is sorted in ascending order. Take the fastest speed.
#$(info "speeds is " $(SPEEDS)) # Good for debugging
else
F_CPU := $(call PARSE_TEENSY,$(BOARD_TAG),menu.speed.$(BOARD_SUB).build.fcpu)
endif
endif
# if boards.txt gets modified, look there, else hard code it
ARCHITECTURE = $(call PARSE_TEENSY,$(BOARD_TAG),build.architecture)
ifeq ($(strip $(ARCHITECTURE)),)
ARCHITECTURE = arm
endif
AVR_TOOLS_DIR = $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/$(ARCHITECTURE))
# define plaform lib dir ignoring teensy's oversight on putting it all in avr
ifndef ARDUINO_PLATFORM_LIB_PATH
ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/avr/libraries
$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR))
endif
########################################################################
# command names
ifndef CC_NAME
CC_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME
CC_NAME := arm-none-eabi-gcc
else
$(call show_config_variable,CC_NAME,[COMPUTED])
endif
endif
ifndef CXX_NAME
CXX_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME
CXX_NAME := arm-none-eabi-g++
else
$(call show_config_variable,CXX_NAME,[COMPUTED])
endif
endif
ifndef AS_NAME
AS_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.as)
ifndef AS_NAME
AS_NAME := arm-none-eabi-gcc-as
else
$(call show_config_variable,AS_NAME,[COMPUTED])
endif
endif
ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME
OBJCOPY_NAME := arm-none-eabi-objcopy
else
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
endif
endif
ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME
OBJDUMP_NAME := arm-none-eabi-objdump
else
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
endif
endif
ifndef AR_NAME
AR_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME
AR_NAME := arm-none-eabi-ar
else
$(call show_config_variable,AR_NAME,[COMPUTED])
endif
endif
ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME
SIZE_NAME := arm-none-eabi-size
else
$(call show_config_variable,SIZE_NAME,[COMPUTED])
endif
endif
ifndef NM_NAME
NM_NAME := $(call PARSE_TEENSY,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME
NM_NAME := arm-none-eabi-gcc-nm
else
$(call show_config_variable,NM_NAME,[COMPUTED])
endif
endif
# processor stuff
ifndef MCU
MCU := $(call PARSE_TEENSY,$(BOARD_TAG),build.cpu)
endif
ifndef MCU_FLAG_NAME
MCU_FLAG_NAME=mcpu
endif
########################################################################
# FLAGS
ifndef USB_TYPE
USB_TYPE = USB_SERIAL
endif
CPPFLAGS += -DLAYOUT_US_ENGLISH -D$(USB_TYPE)
CPPFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.option)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.cppoption)
ifeq ("$(call PARSE_TEENSY,$(BOARD_TAG),build.gnu0x)","true")
CXXFLAGS_STD += -std=gnu++0x
endif
ifeq ("$(call PARSE_TEENSY,$(BOARD_TAG),build.elide_constructors)", "true")
CXXFLAGS += -felide-constructors
endif
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs)
CXXFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpp)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu)
CFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.common)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.defs)
ASFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.S)
LDFLAGS += $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu)
AMCU := $(call PARSE_TEENSY,$(BOARD_TAG),build.mcu)
LDFLAGS += -Wl,--gc-sections,--relax
LINKER_SCRIPTS = -T${ARDUINO_CORE_PATH}/${AMCU}.ld
OTHER_LIBS = $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.libs)
CPUFLAGS = $(call PARSE_TEENSY,$(BOARD_TAG),build.flags.cpu)
# usually defined as per teensy31.build.mcu=mk20dx256 but that isn't valid switch
MCU := $(shell echo ${CPUFLAGS} | sed -n -e 's/.*-mcpu=\([a-zA-Z0-9_-]*\).*/\1/p')
########################################################################
# some fairly odd settings so that 'make upload' works
#
# may require additional patches for Windows support
do_upload: override get_monitor_port=""
AVRDUDE=@true
RESET_CMD = nohup $(ARDUINO_DIR)/hardware/tools/teensy_post_compile -board=$(BOARD_TAG) -tools=$(abspath $(ARDUINO_DIR)/hardware/tools) -path=$(abspath $(OBJDIR)) -file=$(TARGET) > /dev/null ; $(ARDUINO_DIR)/hardware/tools/teensy_reboot
########################################################################
# automatially include Arduino.mk for the user
include $(ARDMK_DIR)/Arduino.mk

View file

@ -0,0 +1,48 @@
.TH ARD-RESET-ARDUINO "1" "January 2017" "ard-reset-arduino 1.5.2" "Arduino CLI Reset"
.SH NAME
ard-reset-arduino - Reset Arduino board
.SH SYNOPSIS
.B ard-reset-arduino
[OPTION]... [PORT]
.SH DESCRIPTION
To reset Arduinos, we either pulse the DTR line or open the USB port
at 1200 baud and close it again.
.SH OPTIONS
.B \-\-verbose
Watch what's going on on STDERR.
.B \-\-period
Specify the DTR pulse width in seconds.
.B \-\-caterina
Reset a Leonardo, Micro, Robot, LilyPadUSB or similar 32u4-based device.
.SH EXAMPLES
ard-reset-arduino /dev/ttyACM0
.PP
ard-reset-arduino \-\-verbose \-\-period=0.1 /dev/cu.usb*
.PP
ard-reset-arduino \-\-verbose \-\-caterina /dev/ttyUSB0
.SH BUGS
There are no known bugs in this application. Please report problems
to the author. Patches are welcome.
.SH AUTHOR
Simon John, git@the-jedi.co.uk
.SH LICENSE
Copyright (c) 2014, Simon John. All rights reserved.
.PP
This file 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.
.PP
This program 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.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
#!/usr/bin/env python
from __future__ import print_function
import serial
import os.path
import argparse
from time import sleep
pyserial_version = None
try:
pyserial_version = int(serial.VERSION[0])
except:
pyserial_version = 2 # less than 2.3
parser = argparse.ArgumentParser(description='Reset an Arduino')
parser.add_argument('--caterina', action='store_true', help='Reset a Leonardo, Micro, Robot or LilyPadUSB.')
parser.add_argument('--verbose', action='store_true', help="Watch what's going on on STDERR.")
parser.add_argument('--period', default=0.1, help='Specify the DTR pulse width in seconds.')
parser.add_argument('port', nargs=1, help='Serial device e.g. /dev/ttyACM0')
args = parser.parse_args()
if args.caterina:
if args.verbose: print('Forcing reset using 1200bps open/close on port %s' % args.port[0])
ser = serial.Serial(args.port[0], 57600)
ser.close()
if pyserial_version < 3:
ser.setBaudrate (1200)
else:
ser.baudrate = 1200
ser.open()
ser.setRTS(True) # RTS line needs to be held high and DTR low
ser.setDTR(False) # (see Arduino IDE source code)
ser.close()
sleep(1)
while not os.path.exists(args.port[0]):
if args.verbose: print('Waiting for %s to come back' % args.port[0])
sleep(1)
if args.verbose: print('%s has come back after reset' % args.port[0])
else:
if args.verbose: print('Setting DTR high on %s for %ss' % (args.port[0],args.period))
ser = serial.Serial(args.port[0], 115200)
ser.setDTR(False)
sleep(args.period)
ser.setDTR(True)
ser.close()

View file

@ -0,0 +1,121 @@
#
# chipKIT extensions for Arduino Makefile
# System part (i.e. project independent)
#
# Copyright (C) 2011, 2012, 2013 Christopher Peplin
# <chris.peplin@rhubarbtech.com>, based on work that is Copyright Martin
# Oldfield
#
# This file 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.
#
# Modified by John Wallbank for Visual Studio
#
# Development changes, John Wallbank,
#
# - made inclusion of WProgram.h optional so that
# including it in the source doesn't mess up compile error line numbers
# - parameterised the routine used to reset the serial port
#
########################################################################
# Makefile distribution path
#
# The show_config_variable is unavailable before we include the common makefile,
# so we defer logging the ARDMK_DIR info until it happens in Arduino.mk
ifndef ARDMK_DIR
# presume it's the same path to our own file
ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
endif
include $(ARDMK_DIR)/Common.mk
ifndef MPIDE_DIR
AUTO_MPIDE_DIR := $(firstword \
$(call dir_if_exists,/usr/share/mpide) \
$(call dir_if_exists,/Applications/Mpide.app/Contents/Resources/Java) )
ifdef AUTO_MPIDE_DIR
MPIDE_DIR = $(AUTO_MPIDE_DIR)
$(call show_config_variable,MPIDE_DIR,[autodetected])
else
echo $(error "mpide_dir is not defined")
endif
else
$(call show_config_variable,MPIDE_DIR,[USER])
endif
ifeq ($(CURRENT_OS),WINDOWS)
ifneq ($(shell echo $(ARDUINO_DIR) | egrep '^(/|[a-zA-Z]:\\)'),)
echo $(error On Windows, MPIDE_DIR must be a relative path)
endif
endif
ifndef MPIDE_PREFERENCES_PATH
AUTO_MPIDE_PREFERENCES_PATH := $(firstword \
$(call dir_if_exists,$(HOME)/.mpide/preferences.txt) \
$(call dir_if_exists,$(HOME)/Library/Mpide/preferences.txt) )
ifdef AUTO_MPIDE_PREFERENCES_PATH
MPIDE_PREFERENCES_PATH = $(AUTO_MPIDE_PREFERENCES_PATH)
$(call show_config_variable,MPIDE_PREFERENCES_PATH,[autodetected])
endif
endif
# The same as in Arduino, the Linux distribution contains avrdude and #
# avrdude.conf in a different location, but for chipKIT it's even slightly
# different than the Linux paths for Arduino, so we have to "double override".
ifeq ($(CURRENT_OS),LINUX)
AVRDUDE_DIR = $(ARDUINO_DIR)/hardware/tools
AVRDUDE = $(AVRDUDE_DIR)/avrdude
AVRDUDE_CONF = $(AVRDUDE_DIR)/avrdude.conf
endif
PIC32_TOOLS_DIR = $(ARDUINO_DIR)/hardware/pic32/compiler/pic32-tools
PIC32_TOOLS_PATH = $(PIC32_TOOLS_DIR)/bin
ALTERNATE_CORE = pic32
ALTERNATE_CORE_PATH = $(MPIDE_DIR)/hardware/pic32
ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(ALTERNATE_CORE)
ARDUINO_PREFERENCES_PATH = $(MPIDE_PREFERENCES_PATH)
ARDUINO_DIR = $(MPIDE_DIR)
CORE_AS_SRCS = $(ARDUINO_CORE_PATH)/vector_table.S \
$(ARDUINO_CORE_PATH)/cpp-startup.S \
$(ARDUINO_CORE_PATH)/crti.S \
$(ARDUINO_CORE_PATH)/crtn.S \
$(ARDUINO_CORE_PATH)/pic32_software_reset.S
ARDUINO_VERSION = 23
CC_NAME = pic32-gcc
CXX_NAME = pic32-g++
AR_NAME = pic32-ar
OBJDUMP_NAME = pic32-objdump
OBJCOPY_NAME = pic32-objcopy
SIZE_NAME = pic32-size
NM_NAME = pic32-nm
OVERRIDE_EXECUTABLES = 1
CC = $(PIC32_TOOLS_PATH)/$(CC_NAME)
CXX = $(PIC32_TOOLS_PATH)/$(CXX_NAME)
AS = $(PIC32_TOOLS_PATH)/$(AS_NAME)
OBJCOPY = $(PIC32_TOOLS_PATH)/$(OBJCOPY_NAME)
OBJDUMP = $(PIC32_TOOLS_PATH)/$(OBJDUMP_NAME)
AR = $(PIC32_TOOLS_PATH)/$(AR_NAME)
SIZE = $(PIC32_TOOLS_PATH)/$(SIZE_NAME)
NM = $(PIC32_TOOLS_PATH)/$(NM_NAME)
LDSCRIPT = $(call PARSE_BOARD,$(BOARD_TAG),ldscript)
LDSCRIPT_FILE = $(ARDUINO_CORE_PATH)/$(LDSCRIPT)
MCU_FLAG_NAME=mprocessor
LDFLAGS += -mdebugger -mno-peripheral-libs -nostartfiles -Wl,--gc-sections
LINKER_SCRIPTS += -T $(ARDUINO_CORE_PATH)/$(LDSCRIPT)
LINKER_SCRIPTS += -T $(ARDUINO_CORE_PATH)/chipKIT-application-COMMON.ld
CPPFLAGS += -mno-smart-io -fno-short-double -fframe-base-loclist \
-g3 -Wcast-align -D_BOARD_MEGA_
CFLAGS_STD =
include $(ARDMK_DIR)/Arduino.mk

View file

@ -0,0 +1 @@
build-*

View file

@ -0,0 +1,23 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Connect a LED to Pin 3. It might be different in different ATtiny micro controllers
int led = 3;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

View file

@ -0,0 +1,13 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
# if you have placed the alternate core in your sketchbook directory, then you can just mention the core name alone.
ALTERNATE_CORE = attiny
# If not, you might have to include the full path.
#ALTERNATE_CORE_PATH = /home/sudar/Dropbox/code/arduino-sketches/hardware/attiny/
BOARD_TAG = attiny85-8
ISP_PORT = /dev/ttyACM*
include $(ARDMK_DIR)/Arduino.mk
# !!! Important. You have to use make ispload to upload when using ISP programmer

View file

@ -0,0 +1,53 @@
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = uno
ARDUINO_LIBS =
include ../../Arduino.mk

View file

@ -0,0 +1,18 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

View file

@ -0,0 +1,130 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = uno
include ../../Arduino.mk
# --- leonardo (or pro micro w/leo bootloader)
#BOARD_TAG = leonardo
#MONITOR_PORT = /dev/ttyACM0
#include /usr/share/arduino/Arduino.mk
# --- mega2560 ide 1.0
#BOARD_TAG = mega2560
#ARDUINO_PORT = /dev/ttyACM0
#include /usr/share/arduino/Arduino.mk
# --- mega2560 ide 1.6
#BOARD_TAG = mega
#BOARD_SUB = atmega2560
#MONITOR_PORT = /dev/ttyACM0
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
#include /usr/share/arduino/Arduino.mk
# --- nano ide 1.0
#BOARD_TAG = nano328
#MONITOR_PORT = /dev/ttyUSB0
#include /usr/share/arduino/Arduino.mk
# --- nano ide 1.6
#BOARD_TAG = nano
#BOARD_SUB = atmega328
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
#include /usr/share/arduino/Arduino.mk
# --- pro mini
#BOARD_TAG = pro5v328
#MONITOR_PORT = /dev/ttyUSB0
#include /usr/share/arduino/Arduino.mk
# --- sparkfun pro micro
#BOARD_TAG = promicro16
#ALTERNATE_CORE = promicro
#BOARDS_TXT = $(HOME)/arduino/hardware/promicro/boards.txt
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/promicro/bootloaders
#BOOTLOADER_PATH = caterina
#BOOTLOADER_FILE = Caterina-promicro16.hex
#ISP_PROG = usbasp
#AVRDUDE_OPTS = -v
#include /usr/share/arduino/Arduino.mk
# --- chipkit
#BOARD_TAG = mega_pic32
#MPIDE_DIR = /where/you/installed/mpide-0023-linux64-20130817-test
#include /usr/share/arduino/chipKIT.mk
# --- pinoccio
#BOARD_TAG = pinoccio256
#ALTERNATE_CORE = pinoccio
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/pinoccio/bootloaders
#BOOTLOADER_PATH = STK500RFR2/release_0.51
#BOOTLOADER_FILE = boot_pinoccio.hex
#CFLAGS_STD = -std=gnu99
#CXXFLAGS_STD = -std=gnu++11
#include /usr/share/arduino/Arduino.mk
# --- fio
#BOARD_TAG = fio
#include /usr/share/arduino/Arduino.mk
# --- atmega-ng ide 1.6
#BOARD_TAG = atmegang
#BOARD_SUB = atmega168
#MONITOR_PORT = /dev/ttyACM0
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
#include /usr/share/arduino/Arduino.mk
# --- arduino-tiny ide 1.0
#ISP_PROG = usbasp
#BOARD_TAG = attiny85at8
#ALTERNATE_CORE = tiny
#ARDUINO_VAR_PATH = $(HOME)/arduino/hardware/tiny/cores/tiny
#ARDUINO_CORE_PATH = $(HOME)/arduino/hardware/tiny/cores/tiny
#AVRDUDE_OPTS = -v
#include /usr/share/arduino/Arduino.mk
# --- arduino-tiny ide 1.6
#ISP_PROG = usbasp
#BOARD_TAG = attiny85at8
#ALTERNATE_CORE = tiny
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
#include /usr/share/arduino/Arduino.mk
# --- damellis attiny ide 1.0
#ISP_PROG = usbasp
#BOARD_TAG = attiny85
#ALTERNATE_CORE = attiny-master
#AVRDUDE_OPTS = -v
#include /usr/share/arduino/Arduino.mk
# --- damellis attiny ide 1.6
#ISP_PROG = usbasp
#BOARD_TAG = attiny
#BOARD_SUB = attiny85
#ALTERNATE_CORE = attiny
#F_CPU = 16000000L
#ARDUINO_DIR = /where/you/installed/arduino-1.6.5
#include /usr/share/arduino/Arduino.mk
# --- teensy3
#BOARD_TAG = teensy31
#ARDUINO_DIR = /where/you/installed/the/patched/teensy/arduino-1.0.6
#include /usr/share/arduino/Teensy.mk
# --- mighty 1284p
#BOARD_TAG = mighty_opt
#BOARDS_TXT = $(HOME)/arduino/hardware/mighty-1284p/boards.txt
#BOOTLOADER_PARENT = $(HOME)/arduino/hardware/mighty-1284p/bootloaders
#BOOTLOADER_PATH = optiboot
#BOOTLOADER_FILE = optiboot_atmega1284p.hex
#ISP_PROG = usbasp
#AVRDUDE_OPTS = -v
#include /usr/share/arduino/Arduino.mk
# --- atmega328p on breadboard
#BOARD_TAG = atmega328bb
#ISP_PROG = usbasp
#AVRDUDE_OPTS = -v
#BOARDS_TXT = $(HOME)/arduino/hardware/breadboard/boards.txt
#include /usr/share/arduino/Arduino.mk

View file

@ -0,0 +1,19 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

View file

@ -0,0 +1,5 @@
BOARD_TAG = mega_pic32
ARDUINO_LIBS =
include ../../chipKIT.mk

View file

@ -0,0 +1,16 @@
# This sample Makefile, explains how you can compile plain AVR C file.
#
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
NO_CORE = Yes
BOARD_TAG = atmega16
MCU = atmega16
F_CPU = 8000000L
ISP_PROG = stk500v1
AVRDUDE_ISP_BAUDRATE = 19200
include ../../Arduino.mk
# !!! Important. You have to use make ispload to upload when using ISP programmer

View file

@ -0,0 +1,38 @@
/*
* (c) Anil Kumar Pugalia, 2010. Email: email@sarika-pugs.com
*
* ATmega48/88/168, ATmega16/32
*
* Example Blink. Toggles all IO pins at 1Hz
*/
#include <avr/io.h>
#include <util/delay.h>
void init_io(void)
{
// 1 = output, 0 = input
DDRB = 0b11111111; // All outputs
DDRC = 0b11111111; // All outputs
DDRD = 0b11111110; // PORTD (RX on PD0). Just for demo
}
int main(void)
{
init_io();
while (1)
{
PORTC = 0xFF;
PORTB = 0xFF;
PORTD = 0xFF;
_delay_ms(500);
PORTC = 0x00;
PORTB = 0x00;
PORTD = 0x00;
_delay_ms(500);
}
return 0;
}

View file

@ -0,0 +1,23 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Connect a LED to Pin 3. It might be different in different ATtiny micro controllers
int led = 3;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

View file

@ -0,0 +1,46 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
# Tested and working with a linuxspi programmer on a remote Raspberry Pi
# Refer to https://github.com/kcuzner/avrdude for linuxspi.
# Should work with ISP as well if you replace $(AVRDUDE_ARD_OPTS) with
# $(AVRDUDE_ISP_OPTS) in the net_set_fuses rule.
# Alternate core from https://code.google.com/p/arduino-tiny
ALTERNATE_CORE = tiny
BOARD_TAG = attiny85at8
# Avrdude config path on the remote Raspberry Pi
AVRDUDE_CONF=/usr/local/etc/avrdude.conf
# Skip the monitor port existance check since it's not on our machine.
FORCE_MONITOR_PORT=true
MONITOR_PORT=/dev/spidev0.0
include ../../Arduino.mk
# Additional rules to use a remote Raspberry Pi programmer
# Note that it's recommended not to use root for this task,
# but to setup spidev access on a normal user instead.
HOST = root@alarmpi
SSH_AVRDUDE = ssh $(HOST) /usr/local/bin/avrdude
CAT_HEX = cat $(TARGET_HEX)
AVRDUDE_UPLOAD_PIPE = -U flash:w:-:i
.PHONY: net_upload net_set_fuses
net_upload: $(TARGET_HEX) verify_size
$(CAT_HEX) | $(SSH_AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
$(AVRDUDE_UPLOAD_PIPE)
net_set_fuses:
ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),)
$(SSH_AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) -e \
$(AVRDUDE_ISP_FUSES_PRE)
endif
ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),)
$(SSH_AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
$(AVRDUDE_ISP_FUSES_POST)
endif

View file

@ -0,0 +1,19 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = teensy31
ARDUINO_LIBS =
include ../../Teensy.mk

View file

@ -0,0 +1,65 @@
/* Blink without Delay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = uno
ARDUINO_LIBS =
include ../../Arduino.mk

View file

@ -0,0 +1,31 @@
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
}
void loop() {
// set the brightness of pin 9:
analogWrite(9, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = uno
ARDUINO_LIBS =
include ../../Arduino.mk

View file

@ -0,0 +1,58 @@
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = uno
ARDUINO_LIBS = LiquidCrystal
include ../../Arduino.mk

View file

@ -0,0 +1,74 @@
### DISCLAIMER
### This is an example Makefile and it MUST be configured to suit your needs.
### For detailed explanations about all of the available options, please refer
### to https://github.com/sudar/Arduino-Makefile/blob/master/arduino-mk-vars.md
### Original project where this Makefile comes from: https://github.com/WeAreLeka/Bare-Arduino-Project
### PROJECT_DIR
### This is the path to where you have created/cloned your project
PROJECT_DIR = /Users/MyUserName/path/to/my/Project
### ARDMK_DIR
### Path to the Arduino-Makefile directory.
ARDMK_DIR = $(PROJECT_DIR)/Arduino-Makefile
### ARDUINO_DIR
### Path to the Arduino application and resources directory.
### On OS X:
ARDUINO_DIR = /Applications/Arduino.app/Contents/Java
### or on Linux: (remove the one you don't want)
ARDUINO_DIR = /usr/share/arduino
### USER_LIB_PATH
### Path to where the your project's libraries are stored.
USER_LIB_PATH := $(PROJECT_DIR)/lib
### BOARD_TAG
### It must be set to the board you are currently using. (i.e uno, mega2560, etc.)
BOARD_TAG = uno
### MONITOR_BAUDRATE
### It must be set to Serial baudrate value you are using.
MONITOR_BAUDRATE = 115200
### AVR_TOOLS_DIR
### Path to the AVR tools directory such as avr-gcc, avr-g++, etc.
### On OS X with `homebrew`:
AVR_TOOLS_DIR = /usr/local
### or on Linux: (remove the one you don't want)
AVR_TOOLS_DIR = /usr
### AVRDUDE
### Path to avrdude directory.
### On OS X with `homebrew`:
AVRDUDE = /usr/local/bin/avrdude
### or on Linux: (remove the one you don't want)
AVRDUDE = /usr/bin/avrdude
### CFLAGS_STD
### Set the C standard to be used during compilation. Documentation (https://github.com/WeAreLeka/Arduino-Makefile/blob/std-flags/arduino-mk-vars.md#cflags_std)
CFLAGS_STD = -std=gnu11
### CXXFLAGS_STD
### Set the C++ standard to be used during compilation. Documentation (https://github.com/WeAreLeka/Arduino-Makefile/blob/std-flags/arduino-mk-vars.md#cxxflags_std)
CXXFLAGS_STD = -std=gnu++11
### CXXFLAGS
### Flags you might want to set for debugging purpose. Comment to stop.
CXXFLAGS += -pedantic -Wall -Wextra
### MONITOR_PORT
### The port your board is connected to. Using an '*' tries all the ports and finds the right one.
MONITOR_PORT = /dev/tty.usbmodem*
### CURRENT_DIR
### Do not touch - used for binaries path
CURRENT_DIR = $(shell basename $(CURDIR))
### OBJDIR
### This is where you put the binaries you just compile using 'make'
OBJDIR = $(PROJECT_DIR)/bin/$(BOARD_TAG)/$(CURRENT_DIR)
### Do not touch - the path to Arduino.mk, inside the ARDMK_DIR
include $(ARDMK_DIR)/Arduino.mk

View file

@ -0,0 +1,9 @@
This folder contains the list of example Arduino sketches and makefile showing
the different usage patterns
- BlinkInAVRC - Shows how to use plain AVR C code
- ATtinyBlink - Shows how to use different cores like ATtiny
- Blink - Shows normal usage
- HelloWorld - Shows how to include Arduino libraries
- SerialPrint - Shows how serial monitor can be used
- BlinkChipKIT - Shows how to use ChipKIT

View file

@ -0,0 +1,5 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = uno
include ../../Arduino.mk

View file

@ -0,0 +1,10 @@
void setup() {
Serial.begin(9600);
Serial.print("Press any key: ");
}
void loop() {
if (Serial.available()) {
Serial.println(Serial.read());
}
}

View file

@ -0,0 +1,20 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
# if you have placed the alternate core in your sketchbook directory, then you can just mention the core name alone.
ALTERNATE_CORE = attiny
# If not, you might have to include the full path.
#ALTERNATE_CORE_PATH = /home/sudar/Dropbox/code/arduino-sketches/hardware/attiny/
# !!! Important. You have to use "make ispload" to upload when using ISP programmer
ISP_PROG = usbasp
# 1.5+ example of submenu cpu
BOARD_TAG = attiny
BOARD_SUB = attiny85
# clock is a submenu too
F_CPU = 16000000L
ARDUINO_LIBS = SoftwareSerial
include /usr/share/arduino/Arduino.mk

View file

@ -0,0 +1,12 @@
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4); // RX, TX
void setup() {
mySerial.begin(9600);
}
void loop() {
mySerial.println(millis());
delay(1000);
}

View file

@ -0,0 +1,6 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = uno
ARDUINO_LIBS = Ethernet SPI
include ../../Arduino.mk

View file

@ -0,0 +1,82 @@
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 178);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("<br />");
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}

View file

@ -0,0 +1,6 @@
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
BOARD_TAG = uno
ARDUINO_LIBS = Wire
include ../../Arduino.mk

View file

@ -0,0 +1,32 @@
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(2, 6); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}

View file

@ -0,0 +1,4 @@
BOARD_TAG = uno
ARDUINO_LIBS =
include ../../Arduino.mk

View file

@ -0,0 +1,95 @@
/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

View file

@ -0,0 +1,49 @@
/*
Melody
Plays a melody
circuit:
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}

View file

@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View file

@ -0,0 +1,23 @@
# How to compile a Deb package
Use these instructions to build your own Deb package from your local sources.
For the latest official packages go to [Debian](http://packages.debian.org/arduino-mk)
or [Ubuntu](https://launchpad.net/ubuntu/+source/arduino-mk) or use apt.
First install the dependencies as root:
apt-get build-dep arduino-mk
apt-get install arduino-core build-essential dpkg-dev fakeroot devscripts
Fetch the Debian source:
apt-get source arduino-mk
Make any local changes to want within the arduino-mk-* directory and update the package version:
cd arduino-mk-*
dch -i
Then compile. This will create a binary Deb:
dpkg-buildpackage -b

View file

@ -0,0 +1,45 @@
# How to compile an RPM
First install the dependencies as root:
```sh
yum install arduino-core rpm-build
# or on Fedora 22+
dnf install arduino-core rpmdevtools
```
From the top-level Arduino-Makefile directory you've checked out of github, run the following (as unprivileged user) to create a compressed tarball using the naming conventions required by rpmbuild:
git archive HEAD --prefix=arduino-mk-1.5/ -o ../arduino-mk-1.5.tar.gz
If you don't already have a rpmbuild setup (e.g. you've not installed the SRPM) you will need to create the directories:
mkdir -p ~/rpmbuild/{SOURCES,SPECS}
Then copy the tarball and specfile into those directories:
cp ../arduino-mk-1.5.tar.gz ~/rpmbuild/SOURCES/
cp packaging/fedora/arduino-mk.spec ~/rpmbuild/SPECS/
Then compile. This will create a binary and source RPM:
cd ~/rpmbuild/SPECS/
rpmbuild -ba arduino-mk.spec
Fedora's AVR compilers use ccache, so you may have to override some of the paths to the AVR tools in your sketch's Makefile, for example:
```Makefile
OVERRIDE_EXECUTABLES = 1
CC = /usr/lib64/ccache/$(CC_NAME)
CXX = /usr/lib64/ccache/$(CXX_NAME)
AS = /usr/bin/$(AS_NAME)
OBJCOPY = /usr/bin/$(OBJCOPY_NAME)
OBJDUMP = /usr/bin/$(OBJDUMP_NAME)
AR = /usr/bin/$(AR_NAME)
SIZE = /usr/bin/$(SIZE_NAME)
NM = /usr/bin/$(NM_NAME)
```
Or if you don't want to use ccache, then just set ```AVR_TOOLS_PATH=/usr``` and none of the above will be necessary.

View file

@ -0,0 +1,70 @@
Name: arduino-mk
Version: 1.5.2
Release: 1%{dist}
Summary: Program your Arduino from the command line
Packager: Simon John <git@the-jedi.co.uk>
URL: https://github.com/sudar/Arduino-Makefile
Source: %{name}-%{version}.tar.gz
Group: Development/Tools
License: LGPLv2+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
Requires: arduino-core pyserial
BuildRequires: arduino-core
%description
Arduino is an open-source electronics prototyping platform based on
flexible, easy-to-use hardware and software. It's intended for artists,
designers, hobbyists, and anyone interested in creating interactive
objects or environments.
This package will install a Makefile to allow for CLI programming of the
Arduino platform.
%prep
%setup -q
%install
mkdir -p %{buildroot}/%{_datadir}/arduino
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/%{_mandir}/man1
mkdir -p %{buildroot}/%{_docdir}/%{name}/examples
install -m 755 -d %{buildroot}/%{_docdir}/%{name}
install -m 755 -d %{buildroot}/%{_docdir}/%{name}/examples
for dir in `find examples -type d` ; do install -m 755 -d %{buildroot}/%{_docdir}/%{name}/$dir ; done
for file in `find examples -type f ! -name .gitignore` ; do install -m 644 $file %{buildroot}/%{_docdir}/%{name}/$file ; done
install -m 644 *.mk arduino-mk-vars.md %{buildroot}/%{_datadir}/arduino
install -m 644 licence.txt %{buildroot}/%{_docdir}/%{name}
install -m 755 bin/ard-reset-arduino %{buildroot}/%{_bindir}/ard-reset-arduino
install -m 644 ard-reset-arduino.1 %{buildroot}/%{_mandir}/man1
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%{_bindir}/ard-reset-arduino
%{_mandir}/man1/ard-reset-arduino.1*
%{_datadir}/arduino/*.mk
%{_datadir}/arduino/arduino-mk-vars.md
%doc %{_docdir}/%{name}/licence.txt
%docdir %{_docdir}/%{name}/examples
%{_docdir}/%{name}/examples
%changelog
* Sat Apr 12 2014 Simon John <git@the-jedi.co.uk>
- Put manpage back.
* Fri Apr 04 2014 Simon John <git@the-jedi.co.uk>
- Removed BuildRequires of python3/pyserial.
* Wed Apr 02 2014 Simon John <git@the-jedi.co.uk>
- Added BuildRequires of python3-pyserial. Need to look into Requires.
* Mon Mar 24 2014 Simon John <git@the-jedi.co.uk>
- Replaced perl/help2man with pyserial for reset script.
* Tue Feb 04 2014 Simon John <git@the-jedi.co.uk>
- Added arduino-mk-vars.md to the files to be installed/packaged.
* Sat Feb 01 2014 Simon John <git@the-jedi.co.uk>
- Updated version.
* Mon Jan 13 2014 Simon John <git@the-jedi.co.uk>
- Removed arduino-mk subdirectory
* Mon Dec 30 2013 Simon John <git@the-jedi.co.uk>
- Initial release.

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd $SCRIPTS_DIR/..
source $SCRIPTS_DIR/bootstrap/chipkit.sh
source $SCRIPTS_DIR/bootstrap/arduino.sh

View file

@ -0,0 +1,44 @@
set -e
BOOTSTRAP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $BOOTSTRAP_DIR/common.sh
echo "Installing dependencies for building for the Arduino"
if [ -z "$ARDUINO_DIR" ] || ! test -e $ARDUINO_DIR || [ $OS == "cygwin" ]; then
echo "Installing Arduino..."
ARDUINO_BASENAME="arduino-1.0.6"
if [ $OS == "cygwin" ]; then
ARDUINO_FILE="$ARDUINO_BASENAME-windows".zip
EXTRACT_COMMAND="unzip -q"
elif [ $OS == "mac" ]; then
ARDUINO_FILE="$ARDUINO_BASENAME-macosx".zip
EXTRACT_COMMAND="unzip -q"
else
ARDUINO_FILE="$ARDUINO_BASENAME-linux64".tgz
EXTRACT_COMMAND="tar -xzf"
fi
ARDUINO_URL=http://arduino.cc/download.php?f=/$ARDUINO_FILE
_pushd $DEPENDENCIES_FOLDER
if ! test -e $ARDUINO_FILE
then
echo "Downloading Arduino IDE..."
download $ARDUINO_URL $ARDUINO_FILE
fi
if ! test -d $ARDUINO_BASENAME
then
echo "Installing Arduino to local folder..."
$EXTRACT_COMMAND $ARDUINO_FILE
echo "Arduino installed"
fi
_popd
fi
echo
echo "${bldgreen}Arduino dependencies installed.$txtrst"

View file

@ -0,0 +1,61 @@
set -e
BOOTSTRAP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $BOOTSTRAP_DIR/common.sh
echo "Installing dependencies for building for the chipKIT"
if [ -z "$MPIDE_DIR" ] || ! test -e $MPIDE_DIR || [ $OS == "cygwin" ]; then
echo "Installing MPIDE..."
if [ $OS == "cygwin" ]; then
MPIDE_BASENAME="mpide-0023-windows-20130715"
MPIDE_FILE="$MPIDE_BASENAME".zip
EXTRACT_COMMAND="unzip -q"
if ! command -v unzip >/dev/null 2>&1; then
_cygwin_error "unzip"
fi
elif [ $OS == "mac" ]; then
MPIDE_BASENAME=mpide-0023-macosx-20130715
MPIDE_FILE="$MPIDE_BASENAME".dmg
else
MPIDE_BASENAME=mpide-0023-linux64-20130817-test
MPIDE_FILE="$MPIDE_BASENAME".tgz
EXTRACT_COMMAND="tar -xzf"
fi
MPIDE_URL=http://chipkit.s3.amazonaws.com/builds/$MPIDE_FILE
_pushd $DEPENDENCIES_FOLDER
if ! test -e $MPIDE_FILE
then
echo "Downloading MPIDE..."
download $MPIDE_URL $MPIDE_FILE
fi
if ! test -d $MPIDE_BASENAME
then
echo "Installing MPIDE to local folder..."
if [ $OS == "mac" ]; then
hdiutil attach $MPIDE_FILE
cp -R /Volumes/Mpide/Mpide.app/Contents/Resources/Java $MPIDE_BASENAME
hdiutil detach /Volumes/Mpide
else
$EXTRACT_COMMAND $MPIDE_FILE
fi
echo "MPIDE installed"
fi
if [ $OS == "cygwin" ]; then
chmod a+x mpide/hardware/pic32/compiler/pic32-tools/bin/*
chmod a+x -R mpide/hardware/pic32/compiler/pic32-tools/pic32mx/
chmod a+x mpide/*.dll
chmod a+x mpide/hardware/tools/avr/bin/*
fi
_popd
fi
echo
echo "${bldgreen}chipKIT dependencies installed.$txtrst"

View file

@ -0,0 +1,190 @@
#!/usr/bin/env bash
set -e
BOOTSTRAP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -z $COMMON_SOURCED ]; then
# TODO this is kind of a hacky way of determining if root is required -
# ideally we wouuld set up a little virtualenv in the dependencies folder
SUDO_CMD=
if command -v sudo >/dev/null 2>&1; then
SUDO_CMD="sudo -E"
if [ -z $CI ] && [ -z $VAGRANT ]; then
echo "The bootstrap script needs to install a few packages to your system as an admin, and we will use the 'sudo' command - enter your password to continue"
$SUDO_CMD ls > /dev/null
fi
fi
KERNEL=`uname`
ARCH=`uname -m`
if [ ${KERNEL:0:7} == "MINGW32" ]; then
OS="windows"
elif [ ${KERNEL:0:6} == "CYGWIN" ]; then
OS="cygwin"
elif [ $KERNEL == "Darwin" ]; then
OS="mac"
else
OS="linux"
if ! command -v lsb_release >/dev/null 2>&1; then
# Arch Linux
if command -v pacman>/dev/null 2>&1; then
$SUDO_CMD pacman -S lsb-release
fi
fi
DISTRO=`lsb_release -si`
fi
die() {
echo >&2 "${bldred}$@${txtrst}"
exit 1
}
_cygwin_error() {
echo
echo "${bldred}Missing \"$1\"${txtrst} - run the Cygwin installer again and select the base package set:"
echo " $CYGWIN_PACKAGES"
echo "After installing the packages, re-run this bootstrap script."
die
}
if ! command -v tput >/dev/null 2>&1; then
if [ $OS == "cygwin" ]; then
echo "OPTIONAL: Install the \"ncurses\" package in Cygwin to get colored shell output"
fi
else
set +e
# These exit with 1 when provisioning in a Vagrant box...?
txtrst=$(tput sgr0) # reset
bldred=${txtbld}$(tput setaf 1)
bldgreen=${txtbld}$(tput setaf 2)
set -e
fi
_pushd() {
pushd $1 > /dev/null
}
_popd() {
popd > /dev/null
}
_wait() {
if [ -z $CI ] && [ -z $VAGRANT ]; then
echo "Press Enter when done"
read
fi
}
_install() {
if [ $OS == "cygwin" ]; then
_cygwin_error $1
elif [ $OS == "mac" ]; then
# brew exists with 1 if it's already installed
set +e
brew install $1
set -e
else
if [ -z $DISTRO ]; then
echo
echo "Missing $1 - install it using your distro's package manager or build from source"
_wait
else
if [ $DISTRO == "arch" ]; then
$SUDO_CMD pacman -S $1
elif [ $DISTRO == "Ubuntu" ]; then
$SUDO_CMD apt-get update -qq
$SUDO_CMD apt-get install $1 -y
else
echo
echo "Missing $1 - install it using your distro's package manager or build from source"
_wait
fi
fi
fi
}
download() {
url=$1
filename=$2
curl $url -L -o $filename
}
if [ `id -u` == 0 ]; then
die "Error: running as root - don't use 'sudo' with this script"
fi
if ! command -v unzip >/dev/null 2>&1; then
_install "unzip"
fi
if ! command -v curl >/dev/null 2>&1; then
if [ $OS == "cygwin" ]; then
_cygwin_error "curl"
else
_install curl
fi
fi
echo "Storing all downloaded dependencies in the \"dependencies\" folder"
DEPENDENCIES_FOLDER="/var/tmp/Arduino-Makefile-testing-dependencies"
mkdir -p $DEPENDENCIES_FOLDER
if ! command -v make >/dev/null 2>&1; then
if [ $OS == "cygwin" ]; then
_cygwin_error "make"
elif [ $OS == "mac" ]; then
die "Missing 'make' - install the Xcode CLI tools"
else
if [ $DISTRO == "arch" ]; then
_install "base-devel"
elif [ $DISTRO == "Ubuntu" ]; then
_install "build-essential"
fi
fi
fi
if [ $DISTRO == "Ubuntu" ] && [ $ARCH == "x86_64" ]; then
_install "libc6-i386"
_install "lib32gcc1"
fi
if ! command -v g++ >/dev/null 2>&1; then
if [ $DISTRO == "Ubuntu" ]; then
_install "g++"
fi
fi
if ! command -v python >/dev/null 2>&1; then
echo "Installing Python..."
_install "python"
fi
if ! command -v pip >/dev/null 2>&1; then
echo "Installing Pip..."
if ! command -v easy_install >/dev/null 2>&1; then
_install "python-setuptools"
fi
if ! command -v easy_install >/dev/null 2>&1; then
die "easy_install not available, can't install pip"
fi
$SUDO_CMD easy_install pip
fi
PIP_SUDO_CMD=
if [ -z $VIRTUAL_ENV ]; then
# Only use sudo if the user doesn't have an active virtualenv
PIP_SUDO_CMD=$SUDO_CMD
fi
$PIP_SUDO_CMD pip install --src dependencies --pre -Ur $BOOTSTRAP_DIR/pip-requirements.txt
COMMON_SOURCED=1
fi

View file

@ -0,0 +1 @@
pyserial==2.7

View file

@ -0,0 +1,67 @@
#!/usr/bin/env bash
TESTS_DIR=examples
failures=()
# These examples cannot be tested easily at the moment as they require
# alternate cores. The MakefileExample doesn't actually contain any source code
# to compile.
NON_TESTABLE_EXAMPLES=(ATtinyBlink MakefileExample TinySoftWareSerial BlinkTeensy BlinkNetworkRPi BlinkInAVRC)
for dir in $TESTS_DIR/*/
do
dir=${dir%*/}
example=${dir##*/}
example_is_testable=true
for non_testable_example in "${NON_TESTABLE_EXAMPLES[@]}"; do
if [[ $example == $non_testable_example ]]; then
example_is_testable=false
break
fi
done
if ! $example_is_testable; then
echo "Skipping non-testable example $example..."
continue
fi
pushd $dir
echo "Compiling $example..."
make_output=`make clean TEST=1`
make_output=`make TEST=1`
if [[ $? -ne 0 ]]; then
failures+=("$example")
echo "Example $example failed"
fi
make_output=`make disasm TEST=1`
if [[ $? -ne 0 ]]; then
failures+=("$example disasm")
echo "Example $example disasm failed"
fi
make_output=`make generate_assembly TEST=1`
if [[ $? -ne 0 ]]; then
failures+=("$example generate_assembly")
echo "Example $example generate_assembly failed"
fi
make_output=`make symbol_sizes TEST=1`
if [[ $? -ne 0 ]]; then
failures+=("$example symbol_sizes")
echo "Example $example symbol_sizes failed"
fi
popd
done
for failure in "${failures[@]}"; do
echo "Example $failure failed"
done
if [[ ${#failures[@]} -eq 0 ]]; then
echo "All tests passed."
else
exit 1
fi

View file

@ -1,119 +0,0 @@
/*
FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
FreeRTOS 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. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <avr/io.h>
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
// GF: added
#define configUSE_MUTEXES 1
#define INCLUDE_xQueueGetMutexHolder 1
// -- done
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 16000000 )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 4 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 85 )
#define configTOTAL_HEAP_SIZE ( (size_t ) ( 4096 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
#define configQUEUE_REGISTRY_SIZE 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 1
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
//##If the following value is set to 1, change the memory managment scheme to heap_2.c:
#define INCLUDE_vTaskDelete 0
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#endif /* FREERTOS_CONFIG_H */

View file

@ -1,263 +1,33 @@
# WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
# Edited by J. Forget
# Released to the Public Domain
# Please read the make user manual!
#
# Additional material for this makefile was submitted by:
# Tim Henigan
# Peter Fleury
# Reiner Patommel
# Sander Pool
# Frederik Rouleau
# Markus Pfaff
#
# On command line:
#
# make NAME=bla.c : compile program bla.c
#
# make clean : Clean out built project files.
#
# make upload : Load the hex file to the device, using avrdude. Please
# customize the avrdude settings below first!
#
# Configuration de la carte
BOARD_TAG = mega
#BOARD_TAG = uno
BOARD_SUB = atmega2560
MONITOR_BAUDRATE = 115200
# MCU name
MCU = atmega2560
# On peut écraser cette valeur en utilisant
# make MONITOR_PORT=/dev/ttyACM1 upload
# (par exemple)
MONITOR_PORT = /dev/ttyACM*
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Flags du compilateur
CFLAGS_STD = -std=gnu11
CXXFLAGS_STD = -std=gnu++11
# Target file name (without extension).
TARGET = principal
OBJS = AC AF position movement debug
CXXFLAGS = -pedantic -Wall -Wextra
CXXFLAGS += -fdiagnostics-color
# Custom
NAME = $(TARGET).c
OBJSC = $(addsuffix .c,$(OBJS))
# Fichires de sortie
TARGET=main
OBJDIR=build
# List C source files here. (C dependencies are automatically generated.)
INSTALL_DIR=./FreeRTOSv9.0.0/FreeRTOS
#DEMO_DIR = $(INSTALL_DIR)/Demo/
SOURCE_DIR = $(INSTALL_DIR)/Source
PORT_DIR = .
USER_LIB_PATH := lib
ARDUINO_QUIET=true
include Arduino-Makefile/Arduino.mk
SRC = \
$(NAME) \
$(OBJSC) \
$(SOURCE_DIR)/tasks.c \
$(SOURCE_DIR)/queue.c \
$(SOURCE_DIR)/list.c \
$(SOURCE_DIR)/timers.c \
$(SOURCE_DIR)/croutine.c \
$(SOURCE_DIR)/portable/MemMang/heap_1.c \
$(PORT_DIR)/port.c
DEBUG_LEVEL=-g
WARNINGS=-Wall
CFLAGS = -D GCC_MEGA_AVR -I. -I$(SOURCE_DIR)/include -I$(DEMO_DIR)/Common/include \
$(DEBUG_LEVEL) \
-fsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
$(WARNINGS) \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Programming support using avrdude. Settings and variables.
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = wiring
AVRDUDE_PORT = /dev/ttyACM0 # programmer connected to serial device
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -D
# ---------------------------------------------------------------------------
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
# Programming support using avrdude.
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(SRC:.c=.o)
# Define all listing files.
LST = $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
finished:
@echo $(MSG_ERRORS_NONE)
end:
@echo $(MSG_END)
@echo
# Program the device.
upload: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
clean clean_list program
# Utilisé par /root pour savoir comment l'envoyer depuis le Raspberry Pi
exportOpts:
@echo "$(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) $(AVRDUDE_UPLOAD_HEX)"
# Envoi sur l'Arduino
send:
make -C ../root $(notdir $(CURDIR)).up

122
arduino/arduino.ino Normal file
View file

@ -0,0 +1,122 @@
#include "Arduino.h"
#include "AX12A.h"
#include <Servo.h>
#define DirectionPin 2
#define BaudRate 1000000
#define ID 14
Servo servoLoquet;
Servo servoPositionBalle;
Servo servoPoussoir;
int pinservoLoquet = 7;
int pinservoPositionBalle = 8;
int pinservoPoussoir = 6;
int relai = 10;
int pos_initial = 512;
int pos_max = 960;
int pos_min = 40;
char lettre;
void setup()
{
Serial.begin(9600);
ax12a.begin(BaudRate, DirectionPin, &Serial1);
servoLoquet.attach(pinservoLoquet);
servoPositionBalle.attach(pinservoPositionBalle);
servoPoussoir.attach(pinservoPoussoir);
pinMode(relai, OUTPUT);
}
void barilletUnCran()
{
ax12a.setEndless(ID, ON);
ax12a.turn(ID, LEFT, 1220);
delay(978);
ax12a.turn(ID, LEFT, 200);
delay(100);
ax12a.turn(ID, LEFT, 1224);
delay(100);
}
void barilletDeuxCrans()
{
ax12a.setEndless(ID, ON);
ax12a.turn(ID, LEFT, 1220);
delay(1955);
ax12a.turn(ID, LEFT, 200);
delay(100);
ax12a.turn(ID, LEFT, 1224);
delay(100);
}
void loop()
{
if (Serial.available()) { // Si le port reçoit une donnée
lettre = Serial.read(); // On lit l'octet et on l'effacera
bool codeInconnu = false;
switch (lettre) {
case 'L': // Ouverture loquet
servoLoquet.write(100);
break;
case 'F': // Fermeture loquet
servoLoquet.write(0);
break;
case 'A': // Position attente balle
servoPositionBalle.write(70);
//delay(2000);
break;
case 'V': // Position évacuation balle
servoPositionBalle.write(0);
//delay(2000);
break;
case 'J': // Position éjection balle
servoPositionBalle.write(180);
//delay(2000);
break;
case 'O': // Pousser balle
// Position basse
servoPoussoir.write(0);
delay(1000);
// Position haute
servoPoussoir.write(120);
delay(1000);
break;
case 'B': // Tourner barillet d'un cran
barilletUnCran();
break;
case 'H': // Tourner de deux crans
barilletDeuxCrans();
break;
case 'R': // Reset barillet
// ax12a.setEndless(ID, OFF);
ax12a.setEndless(ID, ON);
ax12a.turn(ID, LEFT, 0);
break;
case 'T': // Propulsion on
digitalWrite(relai, HIGH);
break;
case 'U': // Propulsion off
digitalWrite(relai, LOW);
break;
case 'P': // Ping
break;
default:
codeInconnu = true;
}
if (codeInconnu) {
Serial.write('E');
Serial.write('C');
} else {
Serial.write(lettre);
}
}

2
arduino/build/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore

6
arduino/configure vendored
View file

@ -1,6 +0,0 @@
#!/usr/bin/env sh
wget "https://sourceforge.net/projects/freertos/files/FreeRTOS/V9.0.0/FreeRTOSv9.0.0.zip/download" -O FreeRTOSv9.0.0.zip -c
unzip "FreeRTOSv9.0.0.zip"
rm "FreeRTOSv9.0.0.zip"

View file

@ -1,35 +0,0 @@
#include <string.h>
#include "debug.h"
#include "AC.h"
#include "position.h"
#include "movement.h"
void TaskDebug(void *pvParameters) {
(void) pvParameters;
for (;;) {
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
// Copie des valeurs à envoyer en debug
memcpy((void*) &debug.actuel, (const void*) &actuel, (unsigned long) sizeof(actuel));
memcpy((void*) &debug.destination, (const void*) &destination, (unsigned long) sizeof(destination));
memcpy((void*) &debug.deltaCoder, (const void*) &deltaCoder, (unsigned long) sizeof(deltaCoder));
debug.movement = movement;
debug.nbCalcPos = nbCalcPos;
nbCalcPos = 0;
// Envoi des valeurs
sendAC(A2CI_DBG, &debug, sizeof(debug));
}
}
void onA2CI_DBG() {
vTaskNotifyGiveFromISR(tDebug, NULL);
}
void configureDebug() {
registerRxHandlerAC(A2CI_DBG, onA2CI_DBG);
xTaskCreate(TaskDebug, "Debug", 128, NULL, 10, &tDebug);;
}

View file

@ -1,18 +0,0 @@
/*
* Outils pour envoyer des informations de debug au chef
*/
#ifndef __DEBUG_H_
#define __DEBUG_H_
#include <FreeRTOS.h>
#include <task.h>
TaskHandle_t tDebug;
struct A2CI_DBGs debug;
void TaskDebug();
void configureDebug();
#endif

1
arduino/lib/AX12A Submodule

@ -0,0 +1 @@
Subproject commit f45322c5e91bc09c8976878d50c92a963ed3db5d

1
arduino/lib/Servo Submodule

@ -0,0 +1 @@
Subproject commit d2a4a47ba97cd0f83f84297bd8d769e797e7ae87

View file

@ -1,90 +0,0 @@
#include "movement.h"
#include "AC.h"
#include "position.h"
void TaskMovement(void* pvParameters)
{
(void)pvParameters;
TickType_t xLastWakeTime;
TickType_t xFrequency = 100 / portTICK_PERIOD_MS;
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction
xLastWakeTime = xTaskGetTickCount();
for (;;) {
// TODO Ici ira le code qui changera les valeurs des moteurs
vTaskDelayUntil(&xLastWakeTime, 1000 / portTICK_PERIOD_MS);
if (movement == C2AD_GOTO) {
actuel.x = destination.x;
actuel.y = destination.y;
actuel.o = destination.o;
}
if (true) { // Arrivé à destination
sendAC(movement, NULL, 0); // On rapporte au chef qu'on a terminé l'action en cours
brake();
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Mettre en veille jusqu'à l'arrivée de la prochaine instruction
xLastWakeTime = xTaskGetTickCount();
} else {
vTaskDelayUntil(&xLastWakeTime, xFrequency);
}
}
}
void brake()
{
movement = C2AD_BRAKE;
// TODO Mettre les IN à ce qu'il faut
}
void onC2AD_BRAKE()
{
brake();
vTaskNotifyGiveFromISR(tMovement, NULL);
}
void freewheel()
{
movement = C2AD_FREE;
// TODO Mettre les IN à ce qu'il faut
}
void onC2AD_FREE()
{
freewheel();
}
void onC2AD_GOTO()
{
movement = C2AD_GOTO;
readAC(&destination, sizeof(struct C2AD_GOTOs));
vTaskNotifyGiveFromISR(tMovement, NULL);
}
void stop()
{
brake();
// TODO Actionneurs
}
void onC2AD_STOP()
{
stop();
sendAC(C2AD_STOP, NULL, 0);
}
void configureMovement()
{
// TODO Configuration des pins
freewheel();
registerRxHandlerAC(C2AD_BRAKE, onC2AD_BRAKE);
registerRxHandlerAC(C2AD_STOP, onC2AD_STOP);
registerRxHandlerAC(C2AD_FREE, onC2AD_FREE);
registerRxHandlerAC(C2AD_GOTO, onC2AD_GOTO);
xTaskCreate(TaskMovement, "Movement", 128, NULL, 2, &tMovement);
}

View file

@ -1,28 +0,0 @@
/*
* Outils assurant le déplacement du robot
*/
#ifndef __MOVEMENT_H_
#define __MOVEMENT_H_
#include <FreeRTOS.h>
#include <task.h>
#include "stdbool.h"
#include "ACsignals.h"
// TODO Définition des pins
TaskHandle_t tMovement;
unsigned char movement;
struct C2AD_GOTOs destination;
// Mouvements qui ne dérangent pas la liaison série
void brake();
void freewheel();
void stop();
void TaskMovement();
void configureMovement();
#endif

View file

@ -1,463 +0,0 @@
/*
FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
FreeRTOS 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. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
/*
Changes from V2.6.0
+ AVR port - Replaced the inb() and outb() functions with direct memory
access. This allows the port to be built with the 20050414 build of
WinAVR.
*/
#include <stdlib.h>
#include <avr/interrupt.h>
#include "FreeRTOS.h"
#include "task.h"
/*-----------------------------------------------------------
* Implementation of functions defined in portable.h for the AVR port.
*----------------------------------------------------------*/
/* Start tasks with interrupts enables. */
#define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x80 )
/* Hardware constants for timer 1. */
#define portCLEAR_COUNTER_ON_MATCH ( ( uint8_t ) 0x08 )
#define portPRESCALE_64 ( ( uint8_t ) 0x03 )
#define portCLOCK_PRESCALER ( ( uint32_t ) 64 )
#define portCOMPARE_MATCH_A_INTERRUPT_ENABLE ( ( uint8_t ) 0x02 )
/*-----------------------------------------------------------*/
/* We require the address of the pxCurrentTCB variable, but don't want to know
any details of its type. */
typedef void TCB_t;
extern volatile TCB_t * volatile pxCurrentTCB;
/*-----------------------------------------------------------*/
/*
* Macro to save all the general purpose registers, the save the stack pointer
* into the TCB.
*
* The first thing we do is save the flags then disable interrupts. This is to
* guard our stack against having a context switch interrupt after we have already
* pushed the registers onto the stack - causing the 32 registers to be on the
* stack twice.
*
* r1 is set to zero as the compiler expects it to be thus, however some
* of the math routines make use of R1.
*
* The interrupts will have been disabled during the call to portSAVE_CONTEXT()
* so we need not worry about reading/writing to the stack pointer.
*/
#define portSAVE_CONTEXT() \
asm volatile ( "push r0 \n\t" \
"in r0, __SREG__ \n\t" \
"cli \n\t" \
"push r0 \n\t" \
"push r1 \n\t" \
"clr r1 \n\t" \
"push r2 \n\t" \
"push r3 \n\t" \
"push r4 \n\t" \
"push r5 \n\t" \
"push r6 \n\t" \
"push r7 \n\t" \
"push r8 \n\t" \
"push r9 \n\t" \
"push r10 \n\t" \
"push r11 \n\t" \
"push r12 \n\t" \
"push r13 \n\t" \
"push r14 \n\t" \
"push r15 \n\t" \
"push r16 \n\t" \
"push r17 \n\t" \
"push r18 \n\t" \
"push r19 \n\t" \
"push r20 \n\t" \
"push r21 \n\t" \
"push r22 \n\t" \
"push r23 \n\t" \
"push r24 \n\t" \
"push r25 \n\t" \
"push r26 \n\t" \
"push r27 \n\t" \
"push r28 \n\t" \
"push r29 \n\t" \
"push r30 \n\t" \
"push r31 \n\t" \
"lds r26, pxCurrentTCB \n\t" \
"lds r27, pxCurrentTCB + 1 \n\t" \
"in r0, 0x3d \n\t" \
"st x+, r0 \n\t" \
"in r0, 0x3e \n\t" \
"st x+, r0 \n\t" \
);
/*
* Opposite to portSAVE_CONTEXT(). Interrupts will have been disabled during
* the context save so we can write to the stack pointer.
*/
#define portRESTORE_CONTEXT() \
asm volatile ( "lds r26, pxCurrentTCB \n\t" \
"lds r27, pxCurrentTCB + 1 \n\t" \
"ld r28, x+ \n\t" \
"out __SP_L__, r28 \n\t" \
"ld r29, x+ \n\t" \
"out __SP_H__, r29 \n\t" \
"pop r31 \n\t" \
"pop r30 \n\t" \
"pop r29 \n\t" \
"pop r28 \n\t" \
"pop r27 \n\t" \
"pop r26 \n\t" \
"pop r25 \n\t" \
"pop r24 \n\t" \
"pop r23 \n\t" \
"pop r22 \n\t" \
"pop r21 \n\t" \
"pop r20 \n\t" \
"pop r19 \n\t" \
"pop r18 \n\t" \
"pop r17 \n\t" \
"pop r16 \n\t" \
"pop r15 \n\t" \
"pop r14 \n\t" \
"pop r13 \n\t" \
"pop r12 \n\t" \
"pop r11 \n\t" \
"pop r10 \n\t" \
"pop r9 \n\t" \
"pop r8 \n\t" \
"pop r7 \n\t" \
"pop r6 \n\t" \
"pop r5 \n\t" \
"pop r4 \n\t" \
"pop r3 \n\t" \
"pop r2 \n\t" \
"pop r1 \n\t" \
"pop r0 \n\t" \
"out __SREG__, r0 \n\t" \
"pop r0 \n\t" \
);
/*-----------------------------------------------------------*/
/*
* Perform hardware setup to enable ticks from timer 1, compare match A.
*/
static void prvSetupTimerInterrupt( void );
/*-----------------------------------------------------------*/
/*
* See header file for description.
*/
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
{
uint16_t usAddress;
/* Place a few bytes of known values on the bottom of the stack.
This is just useful for debugging. */
*pxTopOfStack = 0x11;
pxTopOfStack--;
*pxTopOfStack = 0x22;
pxTopOfStack--;
*pxTopOfStack = 0x33;
pxTopOfStack--;
/* Simulate how the stack would look after a call to vPortYield() generated by
the compiler. */
/*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */
/* The start of the task code will be popped off the stack last, so place
it on first. */
usAddress = ( uint16_t ) pxCode;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--;
usAddress >>= 8;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--;
usAddress >>= 8;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--;
/* Next simulate the stack as if after a call to portSAVE_CONTEXT().
portSAVE_CONTEXT places the flags on the stack immediately after r0
to ensure the interrupts get disabled as soon as possible, and so ensuring
the stack use is minimal should a context switch interrupt occur. */
*pxTopOfStack = ( StackType_t ) 0x00; /* R0 */
pxTopOfStack--;
*pxTopOfStack = portFLAGS_INT_ENABLED;
pxTopOfStack--;
/* Now the remaining registers. The compiler expects R1 to be 0. */
*pxTopOfStack = ( StackType_t ) 0x00; /* R1 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x02; /* R2 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x03; /* R3 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x04; /* R4 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x05; /* R5 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x06; /* R6 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x07; /* R7 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x08; /* R8 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x09; /* R9 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x10; /* R10 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x11; /* R11 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x12; /* R12 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x13; /* R13 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x14; /* R14 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x15; /* R15 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x16; /* R16 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x17; /* R17 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x18; /* R18 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x19; /* R19 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x20; /* R20 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x21; /* R21 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x22; /* R22 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x23; /* R23 */
pxTopOfStack--;
/* Place the parameter on the stack in the expected location. */
usAddress = ( uint16_t ) pvParameters;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--;
usAddress >>= 8;
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x26; /* R26 X */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x27; /* R27 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x28; /* R28 Y */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x29; /* R29 */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x30; /* R30 Z */
pxTopOfStack--;
*pxTopOfStack = ( StackType_t ) 0x031; /* R31 */
pxTopOfStack--;
/*lint +e950 +e611 +e923 */
return pxTopOfStack;
}
/*-----------------------------------------------------------*/
BaseType_t xPortStartScheduler( void )
{
/* Setup the hardware to generate the tick. */
prvSetupTimerInterrupt();
/* Restore the context of the first task that is going to run. */
portRESTORE_CONTEXT();
/* Simulate a function call end as generated by the compiler. We will now
jump to the start of the task the context of which we have just restored. */
asm volatile ( "ret" );
/* Should not get here. */
return pdTRUE;
}
/*-----------------------------------------------------------*/
void vPortEndScheduler( void )
{
/* It is unlikely that the AVR port will get stopped. If required simply
disable the tick interrupt here. */
}
/*-----------------------------------------------------------*/
/*
* Manual context switch. The first thing we do is save the registers so we
* can use a naked attribute.
*/
void vPortYield( void ) __attribute__ ( ( naked ) );
void vPortYield( void )
{
portSAVE_CONTEXT();
vTaskSwitchContext();
portRESTORE_CONTEXT();
asm volatile ( "ret" );
}
/*-----------------------------------------------------------*/
/*
* Context switch function used by the tick. This must be identical to
* vPortYield() from the call to vTaskSwitchContext() onwards. The only
* difference from vPortYield() is the tick count is incremented as the
* call comes from the tick ISR.
*/
void vPortYieldFromTick( void ) __attribute__ ( ( naked ) );
void vPortYieldFromTick( void )
{
portSAVE_CONTEXT();
if( xTaskIncrementTick() != pdFALSE )
{
vTaskSwitchContext();
}
portRESTORE_CONTEXT();
asm volatile ( "ret" );
}
/*-----------------------------------------------------------*/
/*
* Setup timer 1 compare match A to generate a tick interrupt.
*/
static void prvSetupTimerInterrupt( void )
{
uint32_t ulCompareMatch;
uint8_t ucHighByte, ucLowByte;
/* Using 16bit timer 1 to generate the tick. Correct fuses must be
selected for the configCPU_CLOCK_HZ clock. */
ulCompareMatch = configCPU_CLOCK_HZ / configTICK_RATE_HZ;
/* We only have 16 bits so have to scale to get our required tick rate. */
ulCompareMatch /= portCLOCK_PRESCALER;
/* Adjust for correct value. */
ulCompareMatch -= ( uint32_t ) 1;
/* Setup compare match value for compare match A. Interrupts are disabled
before this is called so we need not worry here. */
ucLowByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff );
ulCompareMatch >>= 8;
ucHighByte = ( uint8_t ) ( ulCompareMatch & ( uint32_t ) 0xff );
OCR1AH = ucHighByte;
OCR1AL = ucLowByte;
/* Setup clock source and compare match behaviour. */
ucLowByte = portCLEAR_COUNTER_ON_MATCH | portPRESCALE_64;
TCCR1B = ucLowByte;
/* Enable the interrupt - this is okay as interrupt are currently globally
disabled. */
ucLowByte = TIMSK1;
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
TIMSK1 = ucLowByte;
}
/*-----------------------------------------------------------*/
#if configUSE_PREEMPTION == 1
/*
* Tick ISR for preemptive scheduler. We can use a naked attribute as
* the context is saved at the start of vPortYieldFromTick(). The tick
* count is incremented after the context is saved.
*/
ISR ( TIMER1_COMPA_vect , ISR_NAKED )
{
vPortYieldFromTick();
asm volatile ( "reti" );
}
#else
/*
* Tick ISR for the cooperative scheduler. All this does is increment the
* tick count. We don't need to switch context, this can only be done by
* manual calls to taskYIELD();
*/
ISR ( TIMER1_COMPA_vect , ISR_NAKED )
{
xTaskIncrementTick();
}
#endif

View file

@ -1,51 +0,0 @@
#include "position.h"
#include "AC.h"
#include "AF.h"
#include "dimensions.h"
void TaskPosition(void* pvParameters)
{
(void)pvParameters;
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
for (;;) {
sendAF(F2AI_CODER, NULL, 0);
ulTaskNotifyTake(pdFALSE, portMAX_DELAY); // Wait until new information has arrived
nbCalcPos++;
float adjacent = DISTANCE_BETWEEN_WHEELS;
float opposite = deltaCoder.dR - deltaCoder.dL;
float deltaO = atan(opposite / adjacent);
float deltaD = (deltaCoder.dL + deltaCoder.dR) / 2;
actuel.o += deltaO;
float deltaX = deltaD * cos(actuel.o);
float deltaY = deltaD * sin(actuel.o);
actuel.x += deltaX;
actuel.y += deltaY;
vTaskDelay(xDelay);
}
}
void onF2AI_CODER()
{
readAF(&deltaCoder, sizeof(struct F2AI_CODERs));
vTaskNotifyGiveFromISR(tPosition, NULL);
}
void configurePosition()
{
actuel.x = 0;
actuel.y = 0;
actuel.o = 0;
registerRxHandlerAF(F2AI_CODER, onF2AI_CODER);
xTaskCreate(TaskPosition, "Position", 128, NULL, 2, &tPosition);
;
}

View file

@ -1,24 +0,0 @@
/*
* Outils assurant la connaissance de la postion du robot
*/
#ifndef __POSITION_H_
#define __POSITION_H_
#include <FreeRTOS.h>
#include <task.h>
#include "ACsignals.h"
#include "AFsignals.h"
struct position actuel;
struct F2AI_CODERs deltaCoder;
TaskHandle_t tPosition;
uint16_t nbCalcPos;
void TaskPosition();
void configurePosition();
#endif

View file

@ -1,39 +0,0 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <FreeRTOS.h>
#include <task.h>
#include "AC.h"
#include "AF.h"
#include "position.h"
#include "movement.h"
#include "debug.h"
void TaskBlink(void *pvParameters) {
(void) pvParameters;
TickType_t xLastWakeTime;
TickType_t xFrequency = 200 / portTICK_PERIOD_MS;
DDRB = 0xFF;
xLastWakeTime = xTaskGetTickCount();
for (;;) {
PORTB = PINB ^ 0xFF;
vTaskDelayUntil(&xLastWakeTime, xFrequency);
}
}
int main(void) {
configureAC(); // Doit rester en premier :)
configureAF(); // Doit rester en premier :)
configureMovement();
configurePosition();
configureDebug();
xTaskCreate(TaskBlink, "Blink", 128, NULL, 2, NULL);
sei();
vTaskStartScheduler();
return 0;
}

View file

@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g
## Générateurs de drapeaux pour les bibliothèques
PKG_CONFIG=pkg-config
## Nom des objets communs
OBJS=buttons CF debug diagnostics i2c imu ihm lcd motor movement parcours points position
OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position
OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS)))
# VARIABLES AUTOMATIQUES

232
chef/src/CA.c Normal file
View file

@ -0,0 +1,232 @@
#include "CA.h"
#include <fcntl.h> // O_*
#include <stdio.h> // printf...
#include <stdlib.h> // stuff
#include <string.h> // memcpy
#include <strings.h> // bzero
#include <unistd.h> // read(), write()...
int arduino;
pthread_mutex_t sSendCA;
pthread_t tReaderAC;
rxHandler rxHandlersAC[256];
bool pret;
void printDataCA(void* data, size_t size)
{
printf(" ");
unsigned char* p = data;
for (size_t i = 0; i < size; i++) {
if (*p >= ' ' && *p <= '~') {
printf(" %c", *p);
} else {
printf(" %02x", *p);
}
p++;
}
printf("\n");
}
void configureArduino()
{
// Connection au port série
printf("Connexion à %s... ", ARDUINO_PORTNAME);
fflush(stdout);
arduino = open(ARDUINO_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (arduino < 0) {
printf("Échec !\n");
exit(1);
}
// Configuration du port série
fcntl(arduino, F_SETFL, O_RDWR);
struct termios cfg;
tcgetattr(arduino, &cfg);
cfmakeraw(&cfg);
cfsetispeed(&cfg, CA_BAUDRATE);
cfsetospeed(&cfg, CA_BAUDRATE);
cfg.c_cflag |= (CLOCAL | CREAD);
cfg.c_cflag &= ~PARENB;
cfg.c_cflag &= ~CSTOPB;
cfg.c_cflag &= ~CSIZE;
cfg.c_cflag |= CS8;
cfg.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
cfg.c_oflag &= ~OPOST;
cfg.c_cc[VMIN] = 0;
cfg.c_cc[VTIME] = 10;
if (tcsetattr(arduino, TCSANOW, &cfg) < 0) {
perror("serialConfig.tcsetattr");
exit(1);
}
int status;
ioctl(arduino, TIOCMGET, &status);
status |= TIOCM_DTR;
status |= TIOCM_RTS;
ioctl(arduino, TIOCMSET, &status);
usleep(10 * 1000);
// Flush
unsigned char trash[1024];
read(arduino, &trash, sizeof(trash));
printf("OK!\n");
}
void deconfigureArduino()
{
close(arduino);
printf("Déconnecté\n");
}
void registerRxHandlerCA(unsigned char code, rxHandler handler)
{
rxHandlersAC[code] = handler;
}
void* TaskReaderAC(void* pdata)
{
(void)pdata;
unsigned char code;
for (;;) {
code = readByteCA();
#ifdef PRINTRAWDATA
printf("");
printDataCA(&code, sizeof(code));
#endif
rxHandler handler = rxHandlersAC[code];
if (handler != NULL) {
handler();
} else {
printf("Code inconnu: %x (%c)\n", code, code);
}
}
return NULL;
}
void onA2CD_ERR()
{
struct A2CD_ERRs s;
readCA(&s, sizeof(struct A2CD_ERRs));
printf("Erreur reçue : %c (%2x)\n", s.code, s.code);
}
void setPretCA()
{
pret = true;
}
void doNothingCA()
{
}
void configureCA()
{
configureArduino();
for (int i = 0; i < 256; i++) {
rxHandlersAC[i] = NULL;
}
pthread_mutex_init(&sSendCA, NULL);
pthread_create(&tReaderAC, NULL, TaskReaderAC, NULL);
printf("Attente de réponse du Arduino... ");
fflush(stdout);
// Dans le cas où on aurait laissé l'Arduino en attente de donnée,
// on envoie des pings en boucle jusqu'à ce qu'il nous réponde.
pret = false;
registerRxHandlerCA(C2AD_PING, setPretCA);
while (!pret) {
sendCA(C2AD_PING, NULL, 0);
usleep(100 * 1000);
}
registerRxHandlerCA(C2AD_PING, doNothingCA); // TODO
registerRxHandlerCA(C2AD_PING, NULL);
printf("OK !\n");
registerRxHandlerCA(A2CD_ERR, onA2CD_ERR);
}
void deconfigureCA()
{
deconfigureArduino();
}
void sendByteCA(unsigned char data)
{
write(arduino, &data, sizeof(data));
#ifdef PRINTRAWDATA
printf("");
printDataCA(&data, sizeof(data));
#endif
}
void sendCA(unsigned char code, void* data, size_t size)
{
pthread_mutex_lock(&sSendCA);
sendByteCA(code);
if (size > 0) {
unsigned char* p = data;
for (size_t i = 0; i < size; i++) {
write(arduino, p, sizeof(unsigned char));
p++;
}
// Envoyer plus d'un octet d'un coup curieusement il aime pas ça du tout
}
pthread_mutex_unlock(&sSendCA);
#ifdef PRINTRAWDATA
if (size > 0) {
printf("");
printDataCA(data, size);
}
#endif
}
unsigned char readByteCA()
{
unsigned char c;
while (read(arduino, &c, sizeof(c)) < 1) {
sleep(0);
}
return c;
#ifdef PRINTRAWDATA
printf("");
printDataCA(&c, sizeof(c));
#endif
}
void readCA(void* data, size_t size)
{
size_t remaining = size;
int justRead;
char* p = data;
do {
justRead = read(arduino, p, remaining);
if (justRead > 0) {
p += justRead;
remaining -= justRead;
}
} while (remaining > 0);
#ifdef PRINTRAWDATA
printf("");
printDataCA(data, size);
#endif
}

25
chef/src/CA.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef __CA_H_
#define __CA_H_
#include <sys/ioctl.h>
#include <pthread.h>
#include <termios.h> // baudrates
#include <stdbool.h>
#include "CAsignals.h"
#define ARDUINO_PORTNAME "/dev/ttyACM0"
#define CA_BAUDRATE B9600
// #define PRINTRAWDATA
typedef void (*rxHandler)(void);
void registerRxHandlerCA(unsigned char code, rxHandler handler); // À utiliser après configureCA();
void sendByteCA(unsigned char data); // Privé
void sendCA(unsigned char code, void* data, size_t size);
unsigned char readByteCA(); // À utiliser uniquement depuis un rxHandler
void readCA(void* data, size_t size); // À utiliser uniquement depuis un rxHandler
void configureCA();
void deconfigureCA();
#endif

60
chef/src/CAsignals.h Normal file
View file

@ -0,0 +1,60 @@
/*
* Définition des signaux échagés entre l'Arduino et le chef
*/
#ifndef __CASIGNALS_H_
#define __CASIGNALS_H_
#include <stdint.h>
// Structures used everywhere
// D: Direct
// Sens naturel : Envoi de donnée
// Sens inverse : Accusé de réception
// I: Indirect
// Sens inverse : Demande de donnée
// Sens naturel : Envoi de donnée
// T: Trigger
// Sens inverse : Paramètrage du trigger
// Sens naturel : Envoi de trigger
// Raspberry Pi → Arduino
// Pour le debug
#define C2AD_PING 'P'
#define C2AD_OUVRE_LOQUET 'L'
#define C2AD_FERME_LOQUET 'F'
#define C2AD_POS_BALLE_ATTENTE 'A'
#define C2AD_POS_BALLE_EVACUATION 'V'
#define C2AD_POS_BALLE_EJECTION 'J'
#define C2AD_POUSSER_BALLE 'O'
#define C2AD_BARILLET_SUIVANT 'B'
#define C2AD_BARILLET_SKIP 'H'
#define C2AD_BARILLET_RESET 'R'
#define C2AD_PROPULSION_ON 'T'
#define C2AD_PROPULSION_OFF 'U'
// Arduino → Raspberry Pi
#define A2CD_ERR 'E'
#define A2CD_ERR 'E'
struct __attribute__ ((packed)) A2CD_ERRs {
unsigned char code;
};
#endif

View file

@ -6,7 +6,15 @@
#include <strings.h> // bzero
#include <unistd.h> // read(), write()...
void printData(void* data, size_t size)
int fpga;
pthread_mutex_t sSendCF;
pthread_t tReaderAF;
rxHandler rxHandlersAF[256];
bool pret;
void printDataCF(void* data, size_t size)
{
printf(" ");
unsigned char* p = data;
@ -82,12 +90,12 @@ void deconfigureFpga()
printf("Déconnecté\n");
}
void registerRxHandler(unsigned char code, rxHandler handler)
void registerRxHandlerCF(unsigned char code, rxHandler handler)
{
rxHandlersAC[code] = handler;
rxHandlersAF[code] = handler;
}
void* TaskReaderAC(void* pdata)
void* TaskReaderAF(void* pdata)
{
(void)pdata;
unsigned char code;
@ -96,9 +104,9 @@ void* TaskReaderAC(void* pdata)
#ifdef PRINTRAWDATA
printf("");
printData(&code, sizeof(code));
printDataCF(&code, sizeof(code));
#endif
rxHandler handler = rxHandlersAC[code];
rxHandler handler = rxHandlersAF[code];
if (handler != NULL) {
handler();
} else {
@ -115,12 +123,12 @@ void onF2CD_ERR()
printf("Erreur reçue : %c (%2x)\n", s.code, s.code);
}
void setPret()
void setPretCF()
{
pret = true;
}
void doNothing()
void doNothingCF()
{
}
@ -128,27 +136,27 @@ void configureCF()
{
configureFpga();
for (int i = 0; i < 256; i++) {
rxHandlersAC[i] = NULL;
rxHandlersAF[i] = NULL;
}
pthread_mutex_init(&sSendCF, NULL);
pthread_create(&tReaderAC, NULL, TaskReaderAC, NULL);
pthread_create(&tReaderAF, NULL, TaskReaderAF, NULL);
printf("Attente de réponse du Fpga... ");
fflush(stdout);
// Dans le cas où on aurait laissé l'Fpga en attente de donnée,
// on envoie des pings en boucle jusqu'à ce qu'il nous réponde.
pret = false;
registerRxHandler(C2FD_PING, setPret);
registerRxHandlerCF(C2FD_PING, setPretCF);
while (!pret) {
sendCF(C2FD_PING, NULL, 0);
usleep(100 * 1000);
}
registerRxHandler(C2FD_PING, doNothing); // TODO
registerRxHandler(C2FD_PING, NULL);
registerRxHandlerCF(C2FD_PING, doNothingCF); // TODO
registerRxHandlerCF(C2FD_PING, NULL);
printf("OK !\n");
registerRxHandler(F2CD_ERR, onF2CD_ERR);
registerRxHandlerCF(F2CD_ERR, onF2CD_ERR);
}
void deconfigureCF()
@ -162,7 +170,7 @@ void sendByteCF(unsigned char data)
#ifdef PRINTRAWDATA
printf("");
printData(&data, sizeof(data));
printDataCF(&data, sizeof(data));
#endif
}
@ -184,7 +192,7 @@ void sendCF(unsigned char code, void* data, size_t size)
#ifdef PRINTRAWDATA
if (size > 0) {
printf("");
printData(data, size);
printDataCF(data, size);
}
#endif
}
@ -200,7 +208,7 @@ unsigned char readByteCF()
#ifdef PRINTRAWDATA
printf("");
printData(&c, sizeof(c));
printDataCF(&c, sizeof(c));
#endif
}
@ -219,6 +227,6 @@ void readCF(void* data, size_t size)
#ifdef PRINTRAWDATA
printf("");
printData(data, size);
printDataCF(data, size);
#endif
}

View file

@ -1,5 +1,5 @@
#ifndef __AC_H_
#define __AC_H_
#ifndef __CF_H_
#define __CF_H_
#include <sys/ioctl.h>
#include <pthread.h>
@ -11,16 +11,10 @@
#define FPGA_PORTNAME "/dev/ttyUSB0"
#define CF_BAUDRATE B115200
// #define PRINTRAWDATA
int fpga;
pthread_mutex_t sSendCF;
pthread_t tReaderAC;
//
typedef void (*rxHandler)(void);
rxHandler rxHandlersAC[256];
bool pret;
void registerRxHandler(unsigned char code, rxHandler handler); // À utiliser après configureCF();
void registerRxHandlerCF(unsigned char code, rxHandler handler); // À utiliser après configureCF();
void sendByteCF(unsigned char data); // Privé
void sendCF(unsigned char code, void* data, size_t size);
unsigned char readByteCF(); // À utiliser uniquement depuis un rxHandler

97
chef/src/actionneurs.c Normal file
View file

@ -0,0 +1,97 @@
// Robotech Lille 2017-2018
#include "actionneurs.h"
#include "CA.h"
pthread_mutex_t receptionActionMutex;
pthread_cond_t receptionActionCond;
// On fait un truc de malpropre : étant donné que l'Arduino
// peut faire qu'une seule tache à la fois on suppose que le
// caractère reçu répond à celui qu'on attendait
void configureActionneurs()
{
pthread_mutex_init(&receptionActionMutex, NULL);
pthread_cond_init(&receptionActionCond, NULL);
}
void setLoquet(bool state)
{
attendAction(state ? C2AD_OUVRE_LOQUET : C2AD_FERME_LOQUET);
}
void setPositionBalle(enum positionBalle pos)
{
unsigned char code;
switch (pos) {
case attente:
code = C2AD_POS_BALLE_ATTENTE;
break;
case ejection:
code = C2AD_POS_BALLE_EJECTION;
break;
case evacuation:
code = C2AD_POS_BALLE_EVACUATION;
break;
}
attendAction(code);
}
void pousserBalle()
{
attendAction(C2AD_POUSSER_BALLE);
}
void barilletSuivant()
{
attendAction(C2AD_BARILLET_SUIVANT);
}
void barilletSkip()
{
attendAction(C2AD_BARILLET_SKIP);
}
void barilletReset()
{
attendAction(C2AD_BARILLET_RESET);
}
void setPropulsion(bool state)
{
attendAction(state ? C2AD_PROPULSION_ON : C2AD_PROPULSION_OFF);
}
void resetActionneurs()
{
setPropulsion(false);
barilletReset();
}
void stopActionneurs()
{
setPropulsion(false);
}
void receptionAction()
{
pthread_mutex_lock(&receptionActionMutex);
pthread_cond_signal(&receptionActionCond);
pthread_mutex_unlock(&receptionActionMutex);
}
void attendAction(unsigned char code)
{
pthread_mutex_lock(&receptionActionMutex);
registerRxHandlerCA(code, receptionAction);
sendCA(code, NULL, 0);
pthread_cond_wait(&receptionActionCond, &receptionActionMutex);
pthread_mutex_unlock(&receptionActionMutex);
}
void deconfigureActionneurs()
{
stopActionneurs();
}

38
chef/src/actionneurs.h Normal file
View file

@ -0,0 +1,38 @@
// Robotech Lille 2017-2018
#ifndef __ACTIONNEURS_H_
#define __ACTIONNEURS_H_
#include <stdbool.h>
enum positionBalle {
attente,
evacuation,
ejection
};
// Public
// Specific
// True: Ouvert, False: fermé
void setLoquet(bool state);
void barilletReset();
void barilletSuivant();
void barilletSkip();
void pousserBalle();
void setPositionBalle(enum positionBalle pos);
void setPropulsion(bool state);
// Common
void configureActionneurs();
void resetActionneurs();
void stopActionneurs();
void deconfigureActionneurs();
// Private
void attendAction(unsigned char code);
#endif

View file

@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
@ -5,7 +6,9 @@
#include "diagnostics.h"
#include "lcd.h"
#include "CA.h"
#include "CF.h"
#include "actionneurs.h"
#include "imu.h"
#include "motor.h"
#include "position.h"
@ -38,7 +41,19 @@ bool diagFPGA(void* arg)
bool diagArduino(void* arg)
{
(void)arg;
return false;
recu = false;
registerRxHandlerCA(C2AD_PING, setRecu);
sendCA(C2AD_PING, NULL, 0);
for (int i = 0; i <= DIAGNOSTIC_SERIAL_TIMEOUT; i += DIAGNOSTIC_POLL_INTERVAL) {
if (recu) {
break;
}
usleep(DIAGNOSTIC_POLL_INTERVAL * 1000);
}
registerRxHandlerCA(C2AD_PING, NULL);
return recu;
}
bool diagCodeuse(void* arg)
@ -78,12 +93,48 @@ bool diagIMU(void* arg)
return connectedIMU();
}
void execDiagnostic(char* name, bool (*diagnostic)(void* arg), void* arg)
bool diagJustRun(void* arg)
{
void (*fonction)(void) = arg;
fonction();
return true;
}
void diagSetLoquetOuvert()
{
setLoquet(true);
}
void diagSetLoquetFerme()
{
setLoquet(false);
}
void diagSetPositionBalleAttente()
{
setPositionBalle(attente);
}
void diagSetPositionBalleEjection()
{
setPositionBalle(ejection);
}
void diagSetPositionBalleEvacuation()
{
setPositionBalle(evacuation);
}
void diagSetPropulsionOn()
{
setPropulsion(true);
}
void diagSetPropulsionOff()
{
setPropulsion(false);
}
void execDiagnostic(char* name, diagnosticFunc diag, void* arg)
{
clearLCD();
printToLCD(LCD_LINE_1, name);
printToLCD(LCD_LINE_2, "...");
bool res = diagnostic(arg);
bool res = diag(arg);
if (res) {
printToLCD(LCD_LINE_2, "Ok!");
usleep(DIAGNOSTIC_INTERVAL * 1000);
@ -96,7 +147,7 @@ void execDiagnostic(char* name, bool (*diagnostic)(void* arg), void* arg)
void runDiagnostics()
{
execDiagnostic("Lien FPGA", diagFPGA, NULL);
/* execDiagnostic("Lien Arduino", diagArduino); */
execDiagnostic("Lien Arduino", diagArduino, NULL);
execDiagnostic("Lien IMU", diagIMU, NULL);
int i;
i = 0;
@ -107,4 +158,16 @@ void runDiagnostics()
execDiagnostic("Mot+Cod R AV", diagCodeuse, &i);
i = 3;
execDiagnostic("Mot+Cod R AR", diagCodeuse, &i);
execDiagnostic("Ouverture loquet", diagJustRun, &diagSetLoquetOuvert);
execDiagnostic("Fermeture loquet", diagJustRun, &diagSetLoquetFerme);
execDiagnostic("Reset barillet", diagJustRun, &barilletReset);
execDiagnostic("T+1 barillet", diagJustRun, &barilletSuivant);
execDiagnostic("T+2 barillet", diagJustRun, &barilletSkip);
execDiagnostic("Pousser balle", diagJustRun, &pousserBalle);
execDiagnostic("Pos. attente", diagJustRun, &diagSetPositionBalleAttente);
execDiagnostic("Pos. ejection", diagJustRun, &diagSetPositionBalleEjection);
execDiagnostic("Pos. evacuation", diagJustRun, &diagSetPositionBalleEvacuation);
execDiagnostic("Propulsion off", diagJustRun, &diagSetPropulsionOn);
execDiagnostic("Propulsion on", diagJustRun, &diagSetPropulsionOff);
}

View file

@ -12,10 +12,12 @@
#define DIAGNOSTIC_CODEUSES_DIFF_MIN 100
#define DIAGNOSTIC_TEMPS_ROTATION 250
typedef bool (*diagnosticFunc)(void* arg);
// Public
void runDiagnostics();
// Private
void execDiagnostic(char *name, bool (*diagnostic)(void* arg), void* arg);
void execDiagnostic(char* name, diagnosticFunc diag, void* arg);
#endif

View file

@ -1,4 +1,5 @@
#include "motor.h"
#include "actionneurs.h"
uint8_t tensionToPWM(float V)
{
@ -96,5 +97,5 @@ int freewheel()
int stop()
{
brake();
// TODO Actionneurs
stopActionneurs();
}

View file

@ -6,6 +6,7 @@
#include <unistd.h> // sleep
#include <wiringPi.h>
#include "CA.h"
#include "CF.h"
#include "debug.h"
#include "i2c.h"
@ -35,9 +36,11 @@ int main()
configureDebug();
configureIHM();
configureCF();
configureCA();
configureIMU();
configurePosition();
configureMovement();
configureActionneurs();
startDebug();
startIHM();
@ -49,9 +52,11 @@ int main()
pthread_mutex_lock(&sRunning);
pthread_mutex_lock(&sRunning);
deconfigureActionneurs();
deconfigureMovement();
deconfigurePosition();
deconfigureIMU();
deconfigureCA();
deconfigureCF();
deconfigureIHM();
deconfigureDebug();

View file

@ -112,10 +112,12 @@ chef:
../simu/mat2h.sh
make -C buildroot chef-rebuild
upgrade-chef: chef
upload-chef:
ssh -F sshconf principal true
rsync --rsh 'ssh -F sshconf' --archive --chown root:root buildroot/output/target/opt/chef principal:/opt/
upgrade-chef: chef upload-chef
run:
ssh -F sshconf principal true
ssh -F sshconf principal /etc/init.d/S50chef stop