class pah8011 for mbed
Diff: pixart_pah8011.cpp
- Revision:
- 5:37451de228e4
- Parent:
- 4:cbc49829af39
- Child:
- 6:d196b612b14a
--- a/pixart_pah8011.cpp Fri Oct 27 06:05:38 2017 +0000 +++ b/pixart_pah8011.cpp Fri Oct 27 08:21:32 2017 +0000 @@ -1,27 +1,23 @@ #include "pixart_pah8011.h" + extern "C" { + #include "pah_driver.h" - - typedef void (*debug_printf_handle)(const char *fmt, ...); - - static Serial *g_serial = NULL; + #include "pah_platform_functions.h" + + static I2C *g_i2c = NULL; static uint8_t g_slave_id = 0x15; - - void debug_printf(const char *fmt, ...) + + void disable_debug_printf(const char *fmt, ...) { - if (!g_serial) - return; - - char msg[128]; - va_list marker; - va_start(marker, fmt); - vsprintf(msg, fmt, marker); - va_end(marker); - g_serial->printf(msg); + // do nothing } + + DEBUG_PRINT_HANDLE debug_printf = disable_debug_printf; + bool i2c_write_reg(uint8_t addr, uint8_t data) { @@ -71,10 +67,17 @@ pah_deinit(); } - bool pah8011::init(I2C &i2c, Serial *serial, uint8_t slave_id) + void pah8011::enable_debug_print(DEBUG_PRINT_HANDLE handler) + { + if (handler) + debug_printf = handler; + else + debug_printf = disable_debug_printf; + } + + bool pah8011::init(I2C &i2c, uint8_t slave_id) { g_i2c = &i2c; - g_serial = serial; pah_flags_s flags; memset(&flags, 0, sizeof(flags));