Skip to content

Commit

Permalink
SDK I2C system call implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Mar 2, 2024
1 parent 7144419 commit 369cff7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/librishka.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <librishka/args.h>
#include <librishka/fs.h>
#include <librishka/gpio.h>
#include <librishka/i2c.h>
#include <librishka/int.h>
#include <librishka/io.h>
#include <librishka/memory.h>
Expand Down
76 changes: 76 additions & 0 deletions sdk/librishka_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,80 @@ i32 Args::count() {

string Args::value(u8 index) {
return get_rt_string(rishka_sc_1(RISHKA_SC_ARG_STR, (i64) index));
}

bool I2C::begin(u8 address) {
return (bool) rishka_sc_1(RISHKA_SC_I2C_BEGIN, (i64) address);
}

bool I2C::end() {
return (bool) rishka_sc_0(RISHKA_SC_I2C_END);
}

bool I2C::pins(u8 sda, u8 scl) {
return (bool) rishka_sc_2(RISHKA_SC_I2C_PINS, (i64) sda, (i64) scl);
}

void I2C::flush() {
rishka_sc_0(RISHKA_SC_I2C_FLUSH);
}

void I2C::begin_transmission(u8 address) {
rishka_sc_1(RISHKA_SC_I2C_BEGIN_TRANSMISSION, (i64) address);
}

u8 I2C::end_transmission(bool stop_bit) {
return (u8) rishka_sc_1(RISHKA_SC_I2C_END_TRANSMISSION, (i64) stop_bit);
}

usize I2C::write(u8* data, usize size) {
return (usize) rishka_sc_2(RISHKA_SC_I2C_WRITE, (i64) data, (usize) size);
}

usize I2C::slave_write(u8* data, usize size) {
return (usize) rishka_sc_2(RISHKA_SC_I2C_SLAVE_WRITE, (i64) data, (usize) size);
}

usize I2C::set_buffersize(usize size) {
return (usize) rishka_sc_1(RISHKA_SC_I2C_BUFSIZE, (i64) size);
}

i32 I2C::read() {
return (i32) rishka_sc_0(RISHKA_SC_I2C_READ);
}

i32 I2C::peek() {
return (i32) rishka_sc_0(RISHKA_SC_I2C_PEEK);
}

i32 I2C::available() {
return (i32) rishka_sc_0(RISHKA_SC_I2C_AVAILABLE);
}

usize I2C::request(u8 address, usize size, bool stop_bit) {
return (usize) rishka_sc_3(RISHKA_SC_I2C_REQUEST, (i64) address, (i64) size, (i64) stop_bit);
}

void I2C::on_receive(void (*callback)(int)) {
rishka_sc_1(RISHKA_SC_I2C_ON_RECEIVE, (i64) callback);
}

void I2C::on_request(void (*callback)(void)) {
rishka_sc_1(RISHKA_SC_I2C_ON_RECEIVE, (i64) callback);
}

void I2C::set_timeout(u16 timeout) {
rishka_sc_1(RISHKA_SC_I2C_SET_TIMEOUT, (i64) timeout);
}

u16 I2C::get_timeout() {
return (u16) rishka_sc_0(RISHKA_SC_I2C_GET_TIMEOUT);
}

bool I2C::set_clock(u32 clock) {
return (bool) rishka_sc_1(RISHKA_SC_I2C_SET_CLOCK, (i64) clock);
}

u32 I2C::get_clock() {
return (u32) rishka_sc_0(RISHKA_SC_I2C_GET_CLOCK);
}

0 comments on commit 369cff7

Please sign in to comment.