0.1.0 integer24

This commit is contained in:
Rob Tillaart 2023-06-22 18:50:03 +02:00
parent ce72df8de8
commit d4bc8b6009
15 changed files with 447 additions and 0 deletions

View File

@ -0,0 +1,28 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,13 @@
# Change Log integer24
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.0] - 2023-06-22
- initial version (simple typedef)

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,65 @@
[![Arduino CI](https://github.com/RobTillaart/integer24/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/integer24/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/integer24/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/integer24/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/integer24/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/integer24/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/integer24.svg?maxAge=3600)](https://github.com/RobTillaart/integer24/releases)
# integer24
Arduino library for the integer24 data types uint24_t and int24_t.
## Description
The integer24 is an **experimental** library to implement support
for the following two 24 bit data types:
- **int24_t**
- **uint24_t**
Version 0.1.0 implements a **typedef** for both types.
Note: AVR does support __uint24 and __int24 which uses only 3 bytes.
This allows an UNO to have 30% more elements (in theory).
#### Range
| platform | type | minimum | maximum | notes |
|:----------:|:----------:|:-----------:|:----------:|:-----------|
| AVR | uint24_t | 0 | 16777215 | __uint24 |
| AVR | int24_t | -8388608 | 8388607 | __int24 |
| other | uint24_t | 0 | 4294967296 | uint32_t for now |
| other | int24_t | -2147483648 | 2147483648 | int32_t for now |
Note the range for other platforms may change in the future to
those matching AVR.
If other platforms are known to implement (3byte) int24 data types
please let me know so I can add these.
#### Known limitations
- The AVR uint24_t and int24_t cannot be printed without casting.
- Arduino-CI does not implement __int24 __uint24 so no tests can be done.
## Future
#### Must
- get hands on experience, especially AVR
#### Should
- improve documentation
#### Could
- implement a class for both types?
- implement **printTo()**
#### Won't

View File

@ -0,0 +1,46 @@
// FILE: integer24_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/integer24
#include "Arduino.h"
#include "integer24.h"
uint32_t start, stop;
uint24_t u = 12345;
uint24_t uar[100];
int24_t s = -4321;
int24_t sar[3] = { -1, 1, 0 };
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
Serial.print("INTEGER24_LIB_VERSION: ");
Serial.println(INTEGER24_LIB_VERSION);
uar[99] = random(100);
Serial.println((uint32_t)u);
Serial.println(sizeof(u));
Serial.println((uint32_t)uar[99]);
Serial.println(sizeof(uar));
Serial.println((int32_t)s);
Serial.println(sizeof(s));
Serial.println((uint32_t)sar[2]);
Serial.println(sizeof(sar));
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,93 @@
// FILE: integer24_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/integer24
#include "Arduino.h"
#include "integer24.h"
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
Serial.print("INTEGER24_LIB_VERSION: ");
Serial.println(INTEGER24_LIB_VERSION);
test_uint24_t();
test_int24_t();
}
void loop()
{
}
void test_uint24_t()
{
uint24_t a = 3, b = 2, c;
Serial.println();
Serial.println(__FUNCTION__);
c = a + b;
Serial.println((uint32_t)c);
c = a - b;
Serial.println((uint32_t)c);
c = a * b;
Serial.println((uint32_t)c);
c = a / b;
Serial.println((uint32_t)c);
c = 0;
Serial.println((uint32_t)c++);
Serial.println((uint32_t)c--);
Serial.println((uint32_t)--c);
Serial.println((uint32_t)++c);
c = sqrt(16);
Serial.println((uint32_t)c);
c = sqrt(c);
Serial.println((uint32_t)c);
c = exp(c);
Serial.println((uint32_t)c);
c = pow(c, 1.5);
Serial.println((uint32_t)c);
}
void test_int24_t()
{
int24_t a = -3, b = 2, c;
Serial.println();
Serial.println(__FUNCTION__);
c = a + b;
Serial.println((int32_t)c);
c = a - b;
Serial.println((int32_t)c);
c = a * b;
Serial.println((int32_t)c);
c = a / b;
Serial.println((int32_t)c);
c = 0;
Serial.println((int32_t)c++);
Serial.println((int32_t)c--);
Serial.println((int32_t)--c);
Serial.println((int32_t)++c);
c = sqrt(16);
Serial.println((int32_t)c);
c = sqrt(c);
Serial.println((int32_t)c);
c = exp(c);
Serial.println((int32_t)c);
c = pow(c, 1.5);
Serial.println((int32_t)c);
}
// -- END OF FILE --

View File

@ -0,0 +1,37 @@
#pragma once
//
// FILE: integer24.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2023-06-22
// PURPOSE: Arduino library for the uint24_t and int24_t
// URL: https://github.com/RobTillaart/integer24
//
// uses a simple typedef
#define INTEGER24_LIB_VERSION (F("0.1.0"))
#include "Arduino.h"
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
// supports a true 3 byte data type
typedef __uint24 uint24_t;
typedef __int24 int24_t;
#else
// use 32 bits (4 byte) for now
typedef uint32_t uint24_t;
typedef int32_t int24_t;
#endif
// -- END OF FILE --

View File

@ -0,0 +1,13 @@
# Syntax Colouring Map For integer24
# Data types (KEYWORD1)
integer24 KEYWORD1
uint24_t KEYWORD1
int24_t KEYWORD1
# Methods and Functions (KEYWORD2)
# Constants (LITERAL1)
INTEGER24_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "integer24",
"keywords": "uint24, int24, 24 bits, datatype",
"description": "ACS712 library for Arduino. ",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/integer24.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"headers": "integer24.h"
}

View File

@ -0,0 +1,11 @@
name=integer24
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=integer24 types uint24_t and int24_t for Arduino.
paragraph=AVR does implement a 3 byte version, however cannot print without casting. Other platforms use a typedef of 32 bit.
category=Data Processing
url=https://github.com/RobTillaart/integer24
architectures=*
includes=integer24.h
depends=

View File

@ -0,0 +1,45 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2023-06-22
// PURPOSE: unit tests for the integer24 datatype
// https://github.com/RobTillaart/integer24
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
// #include "integer24.h"
unittest_setup()
{
// fprintf(stderr, "INTEGER24_LIB_VERSION: %s\n", (char *) INTEGER24_LIB_VERSION);
fprintf(stderr, "Arduino CI does not support __uint24 for AVR\n");
fprintf(stderr, "Tests are done in the examples.\n");
}
unittest_teardown()
{
}
unittest_main()
// -- END OF FILE --