|
3 | 3 | * |
4 | 4 | * The MIT License (MIT) |
5 | 5 | * |
6 | | - * Copyright (c) 2016 Scott Shawcroft |
| 6 | + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries |
7 | 7 | * |
8 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | 9 | * of this software and associated documentation files (the "Software"), to deal |
|
25 | 25 | */ |
26 | 26 |
|
27 | 27 | #include "shared-bindings/nativeio/I2C.h" |
| 28 | +#include "shared-bindings/bitbangio/I2C.h" |
28 | 29 | #include "py/mperrno.h" |
29 | 30 | #include "py/nlr.h" |
30 | 31 |
|
31 | 32 | void common_hal_nativeio_i2c_construct(nativeio_i2c_obj_t *self, |
32 | 33 | const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t freq) { |
33 | | - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, |
34 | | - "No hardware support for I2C. Use bitbangio instead.")); |
| 34 | + shared_module_bitbangio_i2c_construct(&self->bitbang, scl, sda, freq); |
35 | 35 | } |
36 | 36 |
|
37 | 37 | void common_hal_nativeio_i2c_deinit(nativeio_i2c_obj_t *self) { |
| 38 | + shared_module_bitbangio_i2c_deinit(&self->bitbang); |
38 | 39 | } |
39 | 40 |
|
40 | 41 | bool common_hal_nativeio_i2c_probe(nativeio_i2c_obj_t *self, uint8_t addr) { |
41 | | - return false; |
| 42 | + return shared_module_bitbangio_i2c_probe(&self->bitbang, addr); |
42 | 43 | } |
43 | 44 |
|
44 | 45 | bool common_hal_nativeio_i2c_try_lock(nativeio_i2c_obj_t *self) { |
45 | | - return false; |
| 46 | + return shared_module_bitbangio_i2c_try_lock(&self->bitbang); |
46 | 47 | } |
47 | 48 |
|
48 | 49 | bool common_hal_nativeio_i2c_has_lock(nativeio_i2c_obj_t *self) { |
49 | | - return false; |
| 50 | + return shared_module_bitbangio_i2c_has_lock(&self->bitbang); |
50 | 51 | } |
51 | 52 |
|
52 | 53 | void common_hal_nativeio_i2c_unlock(nativeio_i2c_obj_t *self) { |
| 54 | + shared_module_bitbangio_i2c_unlock(&self->bitbang); |
53 | 55 | } |
54 | 56 |
|
55 | 57 | uint8_t common_hal_nativeio_i2c_write(nativeio_i2c_obj_t *self, uint16_t addr, |
56 | 58 | const uint8_t * data, size_t len, bool transmit_stop_bit) { |
57 | | - return MP_EIO; |
| 59 | + return shared_module_bitbangio_i2c_write(&self->bitbang, addr, data, len, |
| 60 | + transmit_stop_bit); |
58 | 61 | } |
59 | 62 |
|
60 | 63 | uint8_t common_hal_nativeio_i2c_read(nativeio_i2c_obj_t *self, uint16_t addr, |
61 | 64 | uint8_t * data, size_t len) { |
62 | | - return MP_EIO; |
| 65 | + return shared_module_bitbangio_i2c_read(&self->bitbang, addr, data, len); |
63 | 66 | } |
0 commit comments