Git Product home page Git Product logo

onebit's Introduction

OneBit

Bit operations and bitfields from type-level-up

Providing bit fields that can cross boundaries of the base units and that can even span across multiple units.

The grouping of bits is important because it will allow us to use the functionality of direct port access on an MCU.

This way a write operation is atomic and well identified resulting on a single read/write operation over multiple bits.

Bit-fields are discrete and values set/get do not have to take into account its position inside the unit.

This is type-level only at the index and boundary checking, after that its not only runtime but inlined, making your code expert written.

Operations

get return the bits value

set set the bits value

on set bits on

off set bits off

Examples

Simple Field

//at global scope
uint8_t data[]={0,0};

typedef Bits<uint8_t, uint8_t*, data, 2> MyBit;

MyBit::on();
MyBit::off();
MyBit::set(true);
MyBit::set(0);
MyBit::get();

multi-unit field this field type, MyField, not only crossed the uint8_t base unit boundary but also has a size that exceeds the base unit size.

//at global scope
uint8_t data[]={0,0};

typedef Bits<uint8_t,uint8_t*,data,0,16,uint16_t> MyField;

MyField::set(data,0b1111110000111111);
MyField::get(data);

hardware port address

//arduino uno led: port B, bit #5 ------------------------
//portB input register @0x23
typedef Bits<uint8_t,size_t,0x23,5> LedIn;
//portB mode register @0x24
typedef Bits<uint8_t,size_t,0x24,5> LedMode;
//portB output register @0x25
typedef Bits<uint8_t,size_t,0x25,5> LedOut;

void setup() {
  LedMode::on();//set led pin as output
}

void loop() {
  LedOut::set(!LedIn::get());//toggle led
  delay(500);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.