Skip to content

Commit a2c30ce

Browse files
committed
0.2.3 BitArray
1 parent ab3f015 commit a2c30ce

File tree

16 files changed

+344
-77
lines changed

16 files changed

+344
-77
lines changed

libraries/BitArray/.arduino-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ compile:
22
# Choosing to run compilation tests on 2 different Arduino platforms
33
platforms:
44
- uno
5-
- leonardo
6-
- due
7-
- zero
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
# - mega2560

libraries/BitArray/.github/workflows/arduino_test_runner.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ name: Arduino CI
44
on: [push, pull_request]
55

66
jobs:
7-
arduino_ci:
7+
runTest:
88
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: Arduino-CI/action@master
13-
# Arduino-CI/[email protected]
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb

libraries/BitArray/BitArray.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
//
22
// FILE: BitArray.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.2
4+
// VERSION: 0.2.3
55
// PURPOSE: BitArray library for Arduino
66
// URL: https://github.com/RobTillaart/BitArray
77
// http://forum.arduino.cc/index.php?topic=361167
88
//
9-
// 16 bit clear is faster --> verify correctness
9+
// HISTORY
10+
// 0.1.00 initial version
11+
// 0.1.01 added clear() + fixed set bug
12+
// 0.1.02 first stable version (at last)
13+
// 0.1.03 refactoring
14+
// 0.1.04 improve performance
15+
// 0.1.05 added upper limits
16+
// 0.1.06 refactored
17+
// 0.1.07 private calls inline -> performance & footprint
18+
// 0.1.8 added toggle
19+
// 0.1.9 fix constructor bug
20+
// 0.2.0 2020-03-28 #pragma once, readme, fix Fibonacci demo
21+
// 0.2.1 2020-06-05 fix library.json
22+
// 0.2.2 2020-12-14 add Arduino-CI + unit test
23+
// 0.2.3 2021-10-19 update Arduino-CI + setAll(value)
1024

1125

12-
// 0.2.2 2020-12-14 add arduino-CI + unit test
13-
// 0.2.1 2020-06-05 fix library.json
14-
// 0.2.0 2020-03-28 #pragma once, readme, fix fibnacci demo
15-
//
16-
// 0.1.9 - fix constructor bug
17-
// 0.1.8 - added toggle
18-
// 0.1.07 - private calls inline -> performance & footprint
19-
// 0.1.06 - refactored
20-
// 0.1.05 - added upper limits
21-
// 0.1.04 - improve performance
22-
// 0.1.03 - refactoring
23-
// 0.1.02 - first stabile version (at last)
24-
// 0.1.01 - added clear() + fixed set bug
25-
// 0.1.00 - initial version
26-
//
27-
2826
#include "BitArray.h"
2927

28+
3029
BitArray::BitArray()
3130
{
3231
for (uint8_t i = 0; i < BA_MAX_SEGMENTS; i++)
@@ -35,6 +34,7 @@ BitArray::BitArray()
3534
}
3635
}
3736

37+
3838
BitArray::~BitArray()
3939
{
4040
for (uint8_t i = 0; i < BA_MAX_SEGMENTS; i++)
@@ -43,6 +43,7 @@ BitArray::~BitArray()
4343
}
4444
}
4545

46+
4647
uint8_t BitArray::begin(const uint8_t bits, const uint16_t size)
4748
{
4849
if (bits == 0 || bits > 32)
@@ -67,19 +68,20 @@ uint8_t BitArray::begin(const uint8_t bits, const uint16_t size)
6768
uint16_t b = _bytes;
6869
while (b > 0)
6970
{
70-
_ar[_segments] = (uint8_t*) malloc(min(b, BA_SEGMENT_SIZE));
71+
_ar[_segments] = (uint8_t*) malloc(min(b, (uint16_t) BA_SEGMENT_SIZE));
7172
if (_ar[_segments] == NULL)
7273
{
7374
_error = BA_NO_MEMORY_ERR;
7475
return _error;
7576
}
76-
b = b - min(b, BA_SEGMENT_SIZE);
77+
b = b - min(b, (uint16_t) BA_SEGMENT_SIZE);
7778
_segments++;
7879
}
7980
_error = BA_OK;
8081
return _error;
8182
}
8283

84+
8385
uint32_t BitArray::get(const uint16_t idx)
8486
{
8587
// if (_error != BA_OK) return BA_ERR;
@@ -111,6 +113,7 @@ uint32_t BitArray::set(const uint16_t idx, uint32_t value)
111113
return value;
112114
}
113115

116+
114117
uint32_t BitArray::toggle(const uint16_t idx)
115118
{
116119
// if (_error != BA_OK) return BA_ERR;
@@ -125,6 +128,7 @@ uint32_t BitArray::toggle(const uint16_t idx)
125128
return v;
126129
}
127130

131+
128132
void BitArray::clear()
129133
{
130134
uint16_t b = _bytes;
@@ -133,7 +137,7 @@ void BitArray::clear()
133137
uint8_t *p = _ar[s];
134138
if (p)
135139
{
136-
uint8_t t = min(b, BA_SEGMENT_SIZE);
140+
uint8_t t = min(b, (uint16_t) BA_SEGMENT_SIZE);
137141
b -= t;
138142
while(t--)
139143
{
@@ -144,7 +148,20 @@ void BitArray::clear()
144148
}
145149
}
146150

147-
// 16 bit address usage is faster
151+
152+
153+
void BitArray::setAll(uint32_t value)
154+
{
155+
for (uint16_t i = 0; i < capacity(); i++)
156+
{
157+
set(i, value);
158+
}
159+
}
160+
161+
162+
// 16 bit address usage is faster
163+
// TODO verify correctness
164+
//
148165
// void BitArray::clear()
149166
// {
150167
// uint16_t b = _bytes;
@@ -163,6 +180,7 @@ void BitArray::clear()
163180
// }
164181
// }
165182

183+
166184
// PRIVATE
167185
inline uint8_t BitArray::_bitget(uint16_t pos)
168186
{
@@ -180,6 +198,7 @@ inline uint8_t BitArray::_bitget(uint16_t pos)
180198
return (p[by] >> bi) & 0x01; // bitRead(p[by], bi);
181199
}
182200

201+
183202
inline void BitArray::_bitset(uint16_t pos, uint8_t value)
184203
{
185204
uint8_t se = 0;
@@ -197,6 +216,7 @@ inline void BitArray::_bitset(uint16_t pos, uint8_t value)
197216
else p[by] |= (1 << bi); // bitSet(p[by], bi);
198217
}
199218

219+
200220
inline uint8_t BitArray::_bittoggle(const uint16_t pos)
201221
{
202222
uint8_t se = 0;
@@ -215,4 +235,5 @@ inline uint8_t BitArray::_bittoggle(const uint16_t pos)
215235
return (mask > 0);
216236
}
217237

218-
// END OF FILE
238+
239+
// -- END OF FILE --

libraries/BitArray/BitArray.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
//
33
// FILE: bitArray.h
44
// AUTHOR: Rob dot Tillaart at gmail dot com
5-
// VERSION: 0.2.2
5+
// VERSION: 0.2.3
66
// PURPOSE: BitArray library for Arduino
77
// URL: https://github.com/RobTillaart/BitArray
88

99

1010
// BitArray allows you to make a compact array of objects with a size
1111
// expressed in bits. typically 1..10.
1212
// The interface uses uint32_t as that will be enough for most purposes.
13-
// The main requirement is to optimize storage space
13+
// The main requirement is to optimize storage space.
1414
//
15-
// the bitarray uses an array of segments and the space per segment
15+
// The BitArray uses an array of segments and the space per segment
1616
// may not exceed 256 bytes as this is a limit on some processors.
1717
//
1818
// Originally created to store lot of numbers between 1..6 dice rolls
19-
// the storage is also usable to store e.g. raw 10 bit analogReads
19+
// the storage is also usable to store e.g. raw 10 bit analogRead()'s.
2020
//
2121

2222
#include "Arduino.h"
2323

24-
#define BITARRAY_LIB_VERSION "0.2.2"
24+
#define BITARRAY_LIB_VERSION (F("0.2.3"))
2525

2626

2727

@@ -80,6 +80,7 @@ class BitArray
8080
void clear();
8181
uint32_t get(const uint16_t idx);
8282
uint32_t set(const uint16_t idx, uint32_t value);
83+
void setAll(uint32_t value);
8384
uint32_t toggle(const uint16_t idx);
8485

8586
private:

libraries/BitArray/README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

22
[![Arduino CI](https://github.com/RobTillaart/BitArray/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/BitArray/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/BitArray/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/BitArray/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/BitArray/actions/workflows/jsoncheck.yml)
35
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/BitArray/blob/master/LICENSE)
46
[![GitHub release](https://img.shields.io/github/release/RobTillaart/BitArray.svg?maxAge=3600)](https://github.com/RobTillaart/BitArray/releases)
57

8+
69
# BitArray
710

811
Arduino library for compact array of objects with a size expressed in bits. typically 1..10
912

13+
1014
## Description
1115

1216
The BitArray class allows the user to instantiate an array of elements, each of the same size in bits.
@@ -20,30 +24,42 @@ can take more time. You need to check if your application needs more performance
2024
this library can deliver.
2125

2226
The BitArray library is one from a set of three:
23-
- BitArray for elements of user defined size in bits (values 0 .. 2^n-1)
24-
- BoolArray for elements of 1 bit (values 0 .. 1)
25-
- nybbleArray for elements of 4 bits (values 0 .. 15)
27+
- **BitArray** for elements of user defined size in bits (values 0 .. 2^n-1)
28+
- **BoolArray** for elements of 1 bit (values 0 .. 1)
29+
- **nybbleArray** for elements of 4 bits (values 0 .. 15)
2630

2731

2832
## Operations
33+
2934
In the function **begin(#elementsize, #elements)** the element size and number of elements
3035
needs to be defined. The maximum number of elements is 65535 if memory allows,
3136
the maximum element size is 32.
3237

3338
The basic functions of the class are
34-
- **set(index, value)**
35-
- **get(index)**
36-
- **toggle(index)**
39+
40+
- **set(uint16_t index, uint32_t value)**
41+
- **get(uint16_t index)**
42+
- **toggle(uint16_t index)**
43+
- **setAll(uint32_t value)**
3744
- **clear()**
3845

3946
Check out the examples.
4047

48+
4149
## Notes
4250

43-
The BitArray class dynamicly allocates memory, so called BA_SEGMENTS,
51+
The BitArray class allocates dynamic memory, so called BA_SEGMENTS,
4452
each of 200 bytes.
4553
As the memory size of different processors differ the maximum amount of SEGMENTS
4654
depends on architecture.
4755

4856
The library is tested on AVR architecture only.
4957

58+
59+
## Future
60+
61+
- testing
62+
- functional examples
63+
- documentation
64+
- investigate element size of 64 (for doubles) and beyond.
65+

libraries/BitArray/examples/bitArrayDemo0/bitArrayDemo0.ino

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
// VERSION: 0.1.02
55
// PURPOSE: demo - store 2000 dice rolls
66
// DATE: 14-11-2015
7-
// URL:
8-
//
9-
// Released to the public domain
10-
//
7+
// URL: https://github.com/RobTillaart/BitArray
118

12-
#include "BitArray.h"
139

14-
//#include "avrheap.h"
10+
#include "BitArray.h"
1511

1612
#define SAMPLES 2000
1713

1814
BitArray diceRolls;
1915
int count[7] = { 0, 0, 0, 0, 0, 0, 0 };
2016

21-
//Avrheap myheap;
2217

2318
void setup()
2419
{
@@ -32,8 +27,6 @@ void setup()
3227
if (x == BA_NO_MEMORY_ERR) Serial.println("no mem");
3328
diceRolls.clear();
3429

35-
// myheap.followHeap();
36-
3730
Serial.print("CAPACITY:\t");
3831
Serial.println(diceRolls.capacity());
3932
Serial.print(" MEMORY:\t");
@@ -59,7 +52,6 @@ void setup()
5952
}
6053
Serial.println();
6154

62-
// myheap.followHeap();
6355

6456
Serial.println();
6557
for (int i = 0; i < SAMPLES; i++)
@@ -107,7 +99,11 @@ void setup()
10799
Serial.println("\n finish test...\n");
108100
}
109101

102+
110103
void loop()
111104
{
112105
}
113106

107+
108+
// -- END OF FILE --
109+

libraries/BitArray/examples/bitArrayDemo1/bitArrayDemo1.ino

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
// VERSION: 0.1.00
55
// PURPOSE: demo
66
// DATE: 14-11-2015
7-
// URL:
8-
//
9-
// Released to the public domain
10-
//
7+
// URL: https://github.com/RobTillaart/BitArray
8+
119

1210
#include "BitArray.h"
1311

1412
BitArray b;
1513

14+
1615
void setup()
1716
{
1817
Serial.begin(115200);
@@ -27,6 +26,7 @@ void setup()
2726
test(4, 3000); // 16 steps
2827
}
2928

29+
3030
void test(byte bits, uint16_t samples)
3131
{
3232
b.begin(bits, samples);
@@ -64,3 +64,6 @@ void loop()
6464
{
6565
}
6666

67+
68+
// -- END OF FILE --
69+

0 commit comments

Comments
 (0)