From d1a365fb927b303db6786662f02dfad9a94d91c7 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Thu, 30 Jun 2022 10:26:22 +0800 Subject: [PATCH] i2c: wrap errors to errors::error --- i2c/smbus/libi2c.ha | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/i2c/smbus/libi2c.ha b/i2c/smbus/libi2c.ha index d35b998..84b33dc 100644 --- a/i2c/smbus/libi2c.ha +++ b/i2c/smbus/libi2c.ha @@ -1,38 +1,44 @@ +use errors; use i2c; use io; use rt; export fn access(file: io::file, read_write: u8, command: u8, _size: u32, data: *data) - (int | rt::errno) = { + (int | errors::error) = { const args = ioctl_data { read_write = read_write, command = command, _size = _size, data = data, }; - return rt::ioctl(file: int, i2c::I2C_SMBUS, &args); + return match (rt::ioctl(file: int, i2c::I2C_SMBUS, &args)) { + case let i: int => + yield i; + case let e: rt::errno => + yield errors::errno(e); + }; }; -export fn read_byte_data(file: io::file, command: u8) (u8 | rt::errno) = { +export fn read_byte_data(file: io::file, command: u8) (u8 | errors::error) = { const data = data {...}; access(file, READ, command, BYTE_DATA, &data)?; return data.byte; }; -export fn read_word_data(file: io::file, command: u8) (u16 | rt::errno) = { +export fn read_word_data(file: io::file, command: u8) (u16 | errors::error) = { const data = data {...}; access(file, READ, command, WORD_DATA, &data)?; return data.word; }; -export fn write_byte_data(file: io::file, command: u8, value: u8) (void | rt::errno) = { +export fn write_byte_data(file: io::file, command: u8, value: u8) (void | errors::error) = { const data = data { byte = value, }; access(file, WRITE, command, BYTE_DATA, &data)?; }; -export fn write_word_data(file: io::file, command: u8, value: u16) (void | rt::errno) = { +export fn write_word_data(file: io::file, command: u8, value: u16) (void | errors::error) = { const data = data { word = value, }; -- 2.45.2