Improve build process for Linux

This commit is contained in:
Marcelo Aquino
2016-08-17 23:42:27 -03:00
parent 4d431fbebb
commit b8d4a6a943
14 changed files with 438 additions and 170 deletions
+1
View File
@@ -51,6 +51,7 @@ char *ltoa(long value, char* result, int base);
char *ultoa(long num, char *str, int radix);
char *utoa(int num, char *str, int radix);
char *dtostrf(float f, int width, int decimals, char *result);
void delay(unsigned int millis);
#ifdef __cplusplus
}
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <time.h>
#include "Arduino.h"
/**
@@ -175,3 +176,12 @@ char *dtostrf(float f, int width, int decimals, char *result)
sprintf(result,"%*.*f", width, decimals, f);
return result;
}
void delay(unsigned int millis)
{
struct timespec sleeper;
sleeper.tv_sec = (time_t)(millis / 1000);
sleeper.tv_nsec = (long)(millis % 1000) * 1000000;
nanosleep(&sleeper, NULL);
}
@@ -16,35 +16,11 @@
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* Based on Olivier Mauti work(RF24.h), copyright (C) 2016 Olivier Mauti <olivier@mysensors.org>
* This is a wrapper for maniacbug's RF24 library, copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
*/
#include "RF24.h"
// verify RF24 IRQ defs
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
#if !defined(MY_RF24_IRQ_PIN)
#error Message buffering feature requires MY_RF24_IRQ_PIN to be defined!
#endif
#ifndef SPI_HAS_TRANSACTION
#error RF24 IRQ usage requires transactional SPI support
#endif
#else
#ifdef MY_RX_MESSAGE_BUFFER_SIZE
#error Receive message buffering requires RF24 IRQ usage
#endif
#endif
// pipes
#define BROADCAST_PIPE 1
#define NODE_PIPE 2
// debug
#if defined(MY_DEBUG_VERBOSE_RF24)
#define RF24_DEBUG(x,...) debug(x, ##__VA_ARGS__)
#else
#define RF24_DEBUG(x,...)
#endif
#include <RF24.h>
#include "RF24_Linux.h"
#ifdef MY_RX_MESSAGE_BUFFER_FEATURE
typedef void (*RF24_receiveCallbackType)(void);
@@ -57,7 +33,7 @@
static uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
static uint8_t MY_RF24_NODE_ADDRESS = AUTO;
RF24 _rf24(MY_RF24_CE_PIN, MY_RF24_CS_PIN);
RF24 _rf24(RF24_CE_PIN, RF24_CS_PIN, MY_RF24_SPI_MAX_SPEED);
static void RF24_startListening(void) {
RF24_DEBUG(PSTR("start listening\n"));
+302
View File
@@ -0,0 +1,302 @@
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Marcelo Aquino <marceloaqno@gmail.org>
* Copyright (C) 2016 Marcelo Aquino
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program 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.
*
*/
#ifndef __RF24_LINUX_H__
#define __RF24_LINUX_H__
// SPI settings
#if !defined(MY_RF24_SPI_MAX_SPEED)
#define MY_RF24_SPI_MAX_SPEED BCM2835_SPI_SPEED_8MHZ
#endif
// verify RF24 IRQ defs
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
#if !defined(MY_RF24_IRQ_PIN)
#error Message buffering feature requires MY_RF24_IRQ_PIN to be defined!
#endif
#ifndef SPI_HAS_TRANSACTION
#error RF24 IRQ usage requires transactional SPI support
#endif
#else
#ifdef MY_RX_MESSAGE_BUFFER_SIZE
#error Receive message buffering requires RF24 IRQ usage
#endif
#endif
// pipes
#define BROADCAST_PIPE 1
#define NODE_PIPE 2
// debug
#if defined(MY_DEBUG_VERBOSE_RF24)
#define RF24_DEBUG(x,...) debug(x, ##__VA_ARGS__)
#else
#define RF24_DEBUG(x,...)
#endif
#ifdef LINUX_ARCH_RASPBERRYPI
// CE pin
#ifdef MY_RF24_CE_PIN
#ifdef __RPI_BPLUS
#if MY_RF24_CE_PIN == 3
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_03
#elif MY_RF24_CE_PIN == 5
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_05
#elif MY_RF24_CE_PIN == 7
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_07
#elif MY_RF24_CE_PIN == 8
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_08
#elif MY_RF24_CE_PIN == 10
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_10
#elif MY_RF24_CE_PIN == 11
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_11
#elif MY_RF24_CE_PIN == 12
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_12
#elif MY_RF24_CE_PIN == 13
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_13
#elif MY_RF24_CE_PIN == 15
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_15
#elif MY_RF24_CE_PIN == 16
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_16
#elif MY_RF24_CE_PIN == 18
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_18
#elif MY_RF24_CE_PIN == 19
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_19
#elif MY_RF24_CE_PIN == 21
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_21
#elif MY_RF24_CE_PIN == 22
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_22
#elif MY_RF24_CE_PIN == 23
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_23
#elif MY_RF24_CE_PIN == 24
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_24
#elif MY_RF24_CE_PIN == 26
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_26
#elif MY_RF24_CE_PIN == 29
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_29
#elif MY_RF24_CE_PIN == 31
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_31
#elif MY_RF24_CE_PIN == 32
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_32
#elif MY_RF24_CE_PIN == 33
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_33
#elif MY_RF24_CE_PIN == 35
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_35
#elif MY_RF24_CE_PIN == 36
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_36
#elif MY_RF24_CE_PIN == 37
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_37
#elif MY_RF24_CE_PIN == 38
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_38
#elif MY_RF24_CE_PIN == 40
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_40
#else
#error invalid value for MY_RF24_CE_PIN
#endif
#else
#if MY_RF24_CE_PIN == 3
#define RF24_CE_PIN RPI_V2_GPIO_P1_03
#elif MY_RF24_CE_PIN == 5
#define RF24_CE_PIN RPI_V2_GPIO_P1_05
#elif MY_RF24_CE_PIN == 7
#define RF24_CE_PIN RPI_V2_GPIO_P1_07
#elif MY_RF24_CE_PIN == 8
#define RF24_CE_PIN RPI_V2_GPIO_P1_08
#elif MY_RF24_CE_PIN == 10
#define RF24_CE_PIN RPI_V2_GPIO_P1_10
#elif MY_RF24_CE_PIN == 11
#define RF24_CE_PIN RPI_V2_GPIO_P1_11
#elif MY_RF24_CE_PIN == 12
#define RF24_CE_PIN RPI_V2_GPIO_P1_12
#elif MY_RF24_CE_PIN == 13
#define RF24_CE_PIN RPI_V2_GPIO_P1_13
#elif MY_RF24_CE_PIN == 15
#define RF24_CE_PIN RPI_V2_GPIO_P1_15
#elif MY_RF24_CE_PIN == 16
#define RF24_CE_PIN RPI_V2_GPIO_P1_16
#elif MY_RF24_CE_PIN == 18
#define RF24_CE_PIN RPI_V2_GPIO_P1_18
#elif MY_RF24_CE_PIN == 19
#define RF24_CE_PIN RPI_V2_GPIO_P1_19
#elif MY_RF24_CE_PIN == 21
#define RF24_CE_PIN RPI_V2_GPIO_P1_21
#elif MY_RF24_CE_PIN == 22
#define RF24_CE_PIN RPI_V2_GPIO_P1_22
#elif MY_RF24_CE_PIN == 23
#define RF24_CE_PIN RPI_V2_GPIO_P1_23
#elif MY_RF24_CE_PIN == 24
#define RF24_CE_PIN RPI_V2_GPIO_P1_24
#elif MY_RF24_CE_PIN == 26
#define RF24_CE_PIN RPI_V2_GPIO_P1_26
#elif MY_RF24_CE_PIN == 29
#define RF24_CE_PIN RPI_V2_GPIO_P1_29
#elif MY_RF24_CE_PIN == 31
#define RF24_CE_PIN RPI_V2_GPIO_P1_31
#elif MY_RF24_CE_PIN == 32
#define RF24_CE_PIN RPI_V2_GPIO_P1_32
#elif MY_RF24_CE_PIN == 33
#define RF24_CE_PIN RPI_V2_GPIO_P1_33
#elif MY_RF24_CE_PIN == 35
#define RF24_CE_PIN RPI_V2_GPIO_P1_35
#elif MY_RF24_CE_PIN == 36
#define RF24_CE_PIN RPI_V2_GPIO_P1_36
#elif MY_RF24_CE_PIN == 37
#define RF24_CE_PIN RPI_V2_GPIO_P1_37
#elif MY_RF24_CE_PIN == 38
#define RF24_CE_PIN RPI_V2_GPIO_P1_38
#elif MY_RF24_CE_PIN == 40
#define RF24_CE_PIN RPI_V2_GPIO_P1_40
#else
#error invalid value for MY_RF24_CE_PIN
#endif
#endif
#else
#ifdef __RPI_BPLUS
#define RF24_CE_PIN RPI_BPLUS_GPIO_J8_22
#else
#define RF24_CE_PIN RPI_V2_GPIO_P1_22
#endif
#endif
// CS pin
#ifdef MY_RF24_CS_PIN
#ifdef __RPI_BPLUS
#if MY_RF24_CS_PIN == 3
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_03
#elif MY_RF24_CS_PIN == 5
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_05
#elif MY_RF24_CS_PIN == 7
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_07
#elif MY_RF24_CS_PIN == 8
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_08
#elif MY_RF24_CS_PIN == 10
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_10
#elif MY_RF24_CS_PIN == 11
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_11
#elif MY_RF24_CS_PIN == 12
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_12
#elif MY_RF24_CS_PIN == 13
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_13
#elif MY_RF24_CS_PIN == 15
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_15
#elif MY_RF24_CS_PIN == 16
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_16
#elif MY_RF24_CS_PIN == 18
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_18
#elif MY_RF24_CS_PIN == 19
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_19
#elif MY_RF24_CS_PIN == 21
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_21
#elif MY_RF24_CS_PIN == 22
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_22
#elif MY_RF24_CS_PIN == 23
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_23
#elif MY_RF24_CS_PIN == 24
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_24
#elif MY_RF24_CS_PIN == 26
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_26
#elif MY_RF24_CS_PIN == 29
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_29
#elif MY_RF24_CS_PIN == 31
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_31
#elif MY_RF24_CS_PIN == 32
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_32
#elif MY_RF24_CS_PIN == 33
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_33
#elif MY_RF24_CS_PIN == 35
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_35
#elif MY_RF24_CS_PIN == 36
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_36
#elif MY_RF24_CS_PIN == 37
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_37
#elif MY_RF24_CS_PIN == 38
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_38
#elif MY_RF24_CS_PIN == 40
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_40
#else
#error invalid value for MY_RF24_CS_PIN
#endif
#else
#if MY_RF24_CS_PIN == 3
#define RF24_CS_PIN RPI_V2_GPIO_P1_03
#elif MY_RF24_CS_PIN == 5
#define RF24_CS_PIN RPI_V2_GPIO_P1_05
#elif MY_RF24_CS_PIN == 7
#define RF24_CS_PIN RPI_V2_GPIO_P1_07
#elif MY_RF24_CS_PIN == 8
#define RF24_CS_PIN RPI_V2_GPIO_P1_08
#elif MY_RF24_CS_PIN == 10
#define RF24_CS_PIN RPI_V2_GPIO_P1_10
#elif MY_RF24_CS_PIN == 11
#define RF24_CS_PIN RPI_V2_GPIO_P1_11
#elif MY_RF24_CS_PIN == 12
#define RF24_CS_PIN RPI_V2_GPIO_P1_12
#elif MY_RF24_CS_PIN == 13
#define RF24_CS_PIN RPI_V2_GPIO_P1_13
#elif MY_RF24_CS_PIN == 15
#define RF24_CS_PIN RPI_V2_GPIO_P1_15
#elif MY_RF24_CS_PIN == 16
#define RF24_CS_PIN RPI_V2_GPIO_P1_16
#elif MY_RF24_CS_PIN == 18
#define RF24_CS_PIN RPI_V2_GPIO_P1_18
#elif MY_RF24_CS_PIN == 19
#define RF24_CS_PIN RPI_V2_GPIO_P1_19
#elif MY_RF24_CS_PIN == 21
#define RF24_CS_PIN RPI_V2_GPIO_P1_21
#elif MY_RF24_CS_PIN == 22
#define RF24_CS_PIN RPI_V2_GPIO_P1_22
#elif MY_RF24_CS_PIN == 23
#define RF24_CS_PIN RPI_V2_GPIO_P1_23
#elif MY_RF24_CS_PIN == 24
#define RF24_CS_PIN BCM2835_SPI_CS0
#elif MY_RF24_CS_PIN == 26
#define RF24_CS_PIN BCM2835_SPI_CS1
#elif MY_RF24_CS_PIN == 29
#define RF24_CS_PIN RPI_V2_GPIO_P1_29
#elif MY_RF24_CS_PIN == 31
#define RF24_CS_PIN RPI_V2_GPIO_P1_31
#elif MY_RF24_CS_PIN == 32
#define RF24_CS_PIN RPI_V2_GPIO_P1_32
#elif MY_RF24_CS_PIN == 33
#define RF24_CS_PIN RPI_V2_GPIO_P1_33
#elif MY_RF24_CS_PIN == 35
#define RF24_CS_PIN RPI_V2_GPIO_P1_35
#elif MY_RF24_CS_PIN == 36
#define RF24_CS_PIN RPI_V2_GPIO_P1_36
#elif MY_RF24_CS_PIN == 37
#define RF24_CS_PIN RPI_V2_GPIO_P1_37
#elif MY_RF24_CS_PIN == 38
#define RF24_CS_PIN RPI_V2_GPIO_P1_38
#elif MY_RF24_CS_PIN == 40
#define RF24_CS_PIN RPI_V2_GPIO_P1_40
#else
#error invalid value for MY_RF24_CS_PIN
#endif
#endif
#else
#ifdef __RPI_BPLUS
#define RF24_CS_PIN RPI_BPLUS_GPIO_J8_24
#else
#define RF24_CS_PIN BCM2835_SPI_CS0
#endif
#endif
#endif
#endif