Bluetooth UART support for the Adafruit BluefruitLE SPI, for the University of York Engineering Stage 1 project

Committer:
ajp109
Date:
Fri Mar 12 14:35:25 2021 +0000
Revision:
3:bdfd15be7b82
Parent:
0:a80552d32b80
Remove readme

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ajp109 0:a80552d32b80 1 /**************************************************************************/
ajp109 0:a80552d32b80 2 /*!
ajp109 0:a80552d32b80 3 @file common_header.h
ajp109 0:a80552d32b80 4 @author hathach (Adafruit Industries), ajp109 (University of York)
ajp109 0:a80552d32b80 5
ajp109 0:a80552d32b80 6 @section LICENSE
ajp109 0:a80552d32b80 7
ajp109 0:a80552d32b80 8 Software License Agreement (BSD License)
ajp109 0:a80552d32b80 9
ajp109 0:a80552d32b80 10 Copyright (c) 2016, Adafruit Industries (adafruit.com)
ajp109 0:a80552d32b80 11 All rights reserved.
ajp109 0:a80552d32b80 12
ajp109 0:a80552d32b80 13 Redistribution and use in source and binary forms, with or without
ajp109 0:a80552d32b80 14 modification, are permitted provided that the following conditions are met:
ajp109 0:a80552d32b80 15 1. Redistributions of source code must retain the above copyright
ajp109 0:a80552d32b80 16 notice, this list of conditions and the following disclaimer.
ajp109 0:a80552d32b80 17 2. Redistributions in binary form must reproduce the above copyright
ajp109 0:a80552d32b80 18 notice, this list of conditions and the following disclaimer in the
ajp109 0:a80552d32b80 19 documentation and/or other materials provided with the distribution.
ajp109 0:a80552d32b80 20 3. Neither the name of the copyright holders nor the
ajp109 0:a80552d32b80 21 names of its contributors may be used to endorse or promote products
ajp109 0:a80552d32b80 22 derived from this software without specific prior written permission.
ajp109 0:a80552d32b80 23
ajp109 0:a80552d32b80 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
ajp109 0:a80552d32b80 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ajp109 0:a80552d32b80 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ajp109 0:a80552d32b80 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
ajp109 0:a80552d32b80 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
ajp109 0:a80552d32b80 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ajp109 0:a80552d32b80 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ajp109 0:a80552d32b80 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ajp109 0:a80552d32b80 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ajp109 0:a80552d32b80 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ajp109 0:a80552d32b80 34 */
ajp109 0:a80552d32b80 35 /**************************************************************************/
ajp109 0:a80552d32b80 36
ajp109 0:a80552d32b80 37 #ifndef _COMMON_HEADER_H_
ajp109 0:a80552d32b80 38 #define _COMMON_HEADER_H_
ajp109 0:a80552d32b80 39
ajp109 0:a80552d32b80 40 #include <stdint.h>
ajp109 0:a80552d32b80 41 #include <stdbool.h>
ajp109 0:a80552d32b80 42
ajp109 0:a80552d32b80 43 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 44 // COMPILER
ajp109 0:a80552d32b80 45 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 46 #define STRING_(x) #x // stringify without expand
ajp109 0:a80552d32b80 47 #define XSTRING_(x) STRING_(x) // expand then stringify
ajp109 0:a80552d32b80 48 #define STRING_CONCAT_(a, b) a##b // concat without expand
ajp109 0:a80552d32b80 49 #define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat
ajp109 0:a80552d32b80 50
ajp109 0:a80552d32b80 51 #define ATTR_PACKED __attribute__ ((packed))
ajp109 0:a80552d32b80 52
ajp109 0:a80552d32b80 53 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 54 // ASSERT & VERIFY
ajp109 0:a80552d32b80 55 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 56 //#define ASSERT(condition, err) if ( !(condition) ) return err;
ajp109 0:a80552d32b80 57
ajp109 0:a80552d32b80 58 //------------- Compile-time Assert -------------//
ajp109 0:a80552d32b80 59 #if defined __COUNTER__ && __COUNTER__ != __COUNTER__
ajp109 0:a80552d32b80 60 #define _ASSERT_COUNTER __COUNTER__
ajp109 0:a80552d32b80 61 #else
ajp109 0:a80552d32b80 62 #define _ASSERT_COUNTER __LINE__
ajp109 0:a80552d32b80 63 #endif
ajp109 0:a80552d32b80 64
ajp109 0:a80552d32b80 65 #define ASSERT_STATIC_(const_expr) enum { XSTRING_CONCAT_(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) }
ajp109 0:a80552d32b80 66
ajp109 0:a80552d32b80 67
ajp109 0:a80552d32b80 68 #define VERIFY_(condition) if ( !(condition) ) return false;
ajp109 0:a80552d32b80 69 #define VERIFY_RETURN_(condition, error) if ( !(condition) ) return error;
ajp109 0:a80552d32b80 70
ajp109 0:a80552d32b80 71 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 72 // INLINE FUNCTION
ajp109 0:a80552d32b80 73 //--------------------------------------------------------------------+
ajp109 0:a80552d32b80 74 static inline bool is_within(uint32_t lower, uint32_t value, uint32_t upper)
ajp109 0:a80552d32b80 75 {
ajp109 0:a80552d32b80 76 return (lower <= value) && (value <= upper);
ajp109 0:a80552d32b80 77 }
ajp109 0:a80552d32b80 78
ajp109 0:a80552d32b80 79 // Imitate Arduino constant string declaration
ajp109 0:a80552d32b80 80 #define F(string_literal) (string_literal)
ajp109 0:a80552d32b80 81
ajp109 0:a80552d32b80 82 #endif /* _COMMON_HEADER_H_ */