42#define CHIP_NAME "NXP MMA7660FC"
43#define MANUFACTURER_NAME "NXP"
44#define SUPPLY_VOLTAGE_MIN 2.4f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.294f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define MMA7660FC_ADDRESS 0x98
59#define MMA7660FC_REG_XOUT 0x00
60#define MMA7660FC_REG_YOUT 0x01
61#define MMA7660FC_REG_ZOUT 0x02
62#define MMA7660FC_REG_TILT 0x03
63#define MMA7660FC_REG_SRST 0x04
64#define MMA7660FC_REG_SPCNT 0x05
65#define MMA7660FC_REG_INTSU 0x06
66#define MMA7660FC_REG_MODE 0x07
67#define MMA7660FC_REG_SR 0x08
68#define MMA7660FC_REG_PDET 0x09
69#define MMA7660FC_REG_PD 0x0A
82static uint8_t a_mma7660fc_iic_read(
mma7660fc_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
103static uint8_t a_mma7660fc_iic_write(
mma7660fc_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
140 handle->
debug_print(
"mma7660fc: read tilt failed.\n");
176 handle->
debug_print(
"mma7660fc: read srst failed.\n");
213 handle->
debug_print(
"mma7660fc: read srst failed.\n");
251 handle->
debug_print(
"mma7660fc: write spcnt failed.\n");
286 handle->
debug_print(
"mma7660fc: read spcnt failed.\n");
322 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
327 prev |= (enable << 0);
331 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
367 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
404 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
409 prev |= (enable << 1);
413 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
449 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
486 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
491 prev |= (enable << 2);
495 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
531 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
568 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
573 prev |= (enable << 3);
577 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
613 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
650 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
655 prev |= (enable << 4);
659 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
695 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
732 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
737 prev |= (enable << 7);
741 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
777 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
814 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
819 prev |= (enable << 6);
823 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
859 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
896 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
901 prev |= (enable << 5);
905 handle->
debug_print(
"mma7660fc: write intsu failed.\n");
941 handle->
debug_print(
"mma7660fc: read intsu failed.\n");
978 handle->
debug_print(
"mma7660fc: read mode failed.\n");
987 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1023 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1060 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1065 prev |= (enable << 3);
1069 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1105 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1142 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1147 prev |= (enable << 4);
1151 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1187 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1224 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1229 prev |= (prescaler << 5);
1233 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1269 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1306 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1311 prev |= (type << 6);
1315 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1351 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1388 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1393 prev |= (level << 7);
1397 handle->
debug_print(
"mma7660fc: write mode failed.\n");
1433 handle->
debug_print(
"mma7660fc: read mode failed.\n");
1470 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1475 prev |= (rate << 0);
1479 handle->
debug_print(
"mma7660fc: write sr failed.\n");
1515 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1552 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1557 prev |= (rate << 3);
1561 handle->
debug_print(
"mma7660fc: write sr failed.\n");
1597 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1634 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1639 prev |= (filter << 5);
1643 handle->
debug_print(
"mma7660fc: write sr failed.\n");
1679 handle->
debug_print(
"mma7660fc: read sr failed.\n");
1715 handle->
debug_print(
"mma7660fc: threshold > 31.\n");
1723 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1727 prev &= ~(0x1F << 0);
1728 prev |= (threshold << 0);
1732 handle->
debug_print(
"mma7660fc: write pdet failed.\n");
1768 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1772 *threshold = prev & 0x01F;
1805 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1810 prev |= ((!enable) << 5);
1814 handle->
debug_print(
"mma7660fc: write pdet failed.\n");
1850 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1887 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1892 prev |= ((!enable) << 6);
1896 handle->
debug_print(
"mma7660fc: write pdet failed.\n");
1932 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1969 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
1974 prev |= ((!enable) << 7);
1978 handle->
debug_print(
"mma7660fc: write pdet failed.\n");
2014 handle->
debug_print(
"mma7660fc: read pdet failed.\n");
2052 handle->
debug_print(
"mma7660fc: write pd failed.\n");
2087 handle->
debug_print(
"mma7660fc: read pd failed.\n");
2117 *reg = (uint8_t)((ms - 0.52f) / 0.26f) + 1;
2150 *ms = (float)(reg - 1) * 0.26f + 0.52f;
2183 handle->
debug_print(
"mma7660fc: read tilt failed.\n");
2187 if ((prev & (1 << 0)) != 0)
2194 if ((prev & (1 << 1)) != 0)
2201 if ((prev & (1 << 2)) != 0)
2208 if ((prev & (2 << 2)) != 0)
2215 if ((prev & (5 << 2)) != 0)
2222 if ((prev & (6 << 2)) != 0)
2229 if ((prev & (1 << 5)) != 0)
2236 if ((prev & (1 << 6)) != 0)
2243 if ((prev & (1 << 7)) != 0)
2253 handle->
debug_print(
"mma7660fc: read srst failed.\n");
2257 if ((prev & (1 << 0)) != 0)
2264 if ((prev & (1 << 1)) != 0)
2297 handle->
debug_print(
"mma7660fc: iic_init is null.\n");
2303 handle->
debug_print(
"mma7660fc: iic_deinit is null.\n");
2309 handle->
debug_print(
"mma7660fc: iic_read is null.\n");
2315 handle->
debug_print(
"mma7660fc: iic_write is null.\n");
2321 handle->
debug_print(
"mma7660fc: receive_callback is null.\n");
2327 handle->
debug_print(
"mma7660fc: delay_ms is null.\n");
2334 handle->
debug_print(
"mma7660fc: iic init failed.\n");
2371 handle->
debug_print(
"mma7660fc: read mode failed.\n");
2379 handle->
debug_print(
"mma7660fc: write mode failed.\n");
2385 handle->
debug_print(
"mma7660fc: iic deinit failed.\n");
2424 handle->
debug_print(
"mma7660fc: read data failed.\n");
2428 buf[0] &= ~(1 << 7);
2429 buf[1] &= ~(1 << 7);
2430 buf[2] &= ~(1 << 7);
2431 if ((buf[0] & (1 << 6)) != 0)
2433 handle->
debug_print(
"mma7660fc: data is invalid.\n");
2437 if ((buf[1] & (1 << 6)) != 0)
2439 handle->
debug_print(
"mma7660fc: data is invalid.\n");
2443 if ((buf[2] & (1 << 6)) != 0)
2445 handle->
debug_print(
"mma7660fc: data is invalid.\n");
2450 if ((buf[0] & (1 << 5)) != 0)
2452 raw[0] = (int8_t)(buf[0] | (3 << 6));
2453 g[0] = (float)(raw[0] / 21.33f);
2457 raw[0] = (int8_t)buf[0];
2458 g[0] = (float)(raw[0] / 21.33f);
2460 if ((buf[1] & (1 << 5)) != 0)
2462 raw[1] = (int8_t)(buf[1] | (3 << 6));
2463 g[1] = (float)(raw[1] / 21.33f);
2467 raw[1] = (int8_t)buf[1];
2468 g[1] = (float)(raw[1] / 21.33f);
2470 if ((buf[2] & (1 << 5)) != 0)
2472 raw[2] = (int8_t)(buf[2] | (3 << 6));
2473 g[2] = (float)(raw[2] / 21.33f);
2477 raw[2] = (int8_t)buf[2];
2478 g[2] = (float)(raw[2] / 21.33f);
2508 return a_mma7660fc_iic_write(handle, reg, buf, len);
2535 return a_mma7660fc_iic_read(handle, reg, buf, len);
#define MMA7660FC_REG_PDET
#define MMA7660FC_REG_MODE
#define MMA7660FC_REG_XOUT
chip register definition
#define MMA7660FC_REG_SRST
#define SUPPLY_VOLTAGE_MAX
#define MMA7660FC_REG_INTSU
#define MANUFACTURER_NAME
#define MMA7660FC_REG_TILT
#define SUPPLY_VOLTAGE_MIN
#define MMA7660FC_ADDRESS
chip address definition
#define CHIP_NAME
chip information definition
#define MMA7660FC_REG_SPCNT
driver mma7660fc header file
uint8_t mma7660fc_get_sleep_count(mma7660fc_handle_t *handle, uint8_t *count)
get sleep count
uint8_t mma7660fc_set_auto_wake_up(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto wake up
uint8_t mma7660fc_get_auto_sleep_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get auto sleep interrupt status
uint8_t mma7660fc_init(mma7660fc_handle_t *handle)
initialize the chip
mma7660fc_interrupt_pin_type_t
mma7660fc interrupt pin type enumeration definition
mma7660fc_bool_t
mma7660fc bool enumeration definition
uint8_t mma7660fc_get_shake_x_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get shake x interrupt status
uint8_t mma7660fc_set_shake_x_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake x interrupt
uint8_t mma7660fc_get_shake_y_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get shake y interrupt status
uint8_t mma7660fc_get_tap_y_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get tap y detection status
uint8_t mma7660fc_get_shake_z_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get shake z interrupt status
uint8_t mma7660fc_get_auto_wake_up(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get auto wake up status
uint8_t mma7660fc_set_sleep_counter_prescaler(mma7660fc_handle_t *handle, mma7660fc_sleep_counter_prescaler_t prescaler)
set sleep counter prescaler
uint8_t mma7660fc_get_tilt_status(mma7660fc_handle_t *handle, uint8_t *status)
get tilt status
uint8_t mma7660fc_set_interrupt_pin_type(mma7660fc_handle_t *handle, mma7660fc_interrupt_pin_type_t type)
set interrupt pin type
uint8_t mma7660fc_tap_pulse_debounce_convert_to_data(mma7660fc_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to tap pulse debounce
uint8_t mma7660fc_get_auto_sleep(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get auto sleep status
uint8_t mma7660fc_read(mma7660fc_handle_t *handle, int8_t raw[3], float g[3])
read the data
uint8_t mma7660fc_set_tap_detection_threshold(mma7660fc_handle_t *handle, uint8_t threshold)
set tap detection threshold
uint8_t mma7660fc_deinit(mma7660fc_handle_t *handle)
close the chip
uint8_t mma7660fc_set_shake_z_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake z interrupt
uint8_t mma7660fc_tap_pulse_debounce_convert_to_register(mma7660fc_handle_t *handle, float ms, uint8_t *reg)
convert tap pulse debounce to the register raw data
uint8_t mma7660fc_get_sleep_counter_prescaler(mma7660fc_handle_t *handle, mma7660fc_sleep_counter_prescaler_t *prescaler)
get sleep counter prescaler
uint8_t mma7660fc_get_update_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get update interrupt status
uint8_t mma7660fc_info(mma7660fc_info_t *info)
get chip's information
uint8_t mma7660fc_set_tilt_debounce_filter(mma7660fc_handle_t *handle, mma7660fc_tilt_debounce_filter_t filter)
set tilt debounce filter
uint8_t mma7660fc_set_auto_wake_rate(mma7660fc_handle_t *handle, mma7660fc_auto_wake_rate_t rate)
set auto wake rate
struct mma7660fc_info_s mma7660fc_info_t
mma7660fc information structure definition
uint8_t mma7660fc_get_tap_pulse_debounce_count(mma7660fc_handle_t *handle, uint8_t *count)
get tap pulse debounce count
uint8_t mma7660fc_get_up_down_right_left_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get up down right left interrupt status
uint8_t mma7660fc_set_mode(mma7660fc_handle_t *handle, mma7660fc_mode_t mode)
set mode
uint8_t mma7660fc_set_auto_sleep_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto sleep interrupt
uint8_t mma7660fc_get_front_back_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get front back interrupt status
uint8_t mma7660fc_get_tilt_debounce_filter(mma7660fc_handle_t *handle, mma7660fc_tilt_debounce_filter_t *filter)
get tilt debounce filter
uint8_t mma7660fc_get_tap_detection_rate(mma7660fc_handle_t *handle, mma7660fc_auto_sleep_rate_t *rate)
get tap detection rate
struct mma7660fc_handle_s mma7660fc_handle_t
mma7660fc handle structure definition
mma7660fc_interrupt_active_level_t
mma7660fc interrupt active level enumeration definition
uint8_t mma7660fc_set_update_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable update interrupt status
uint8_t mma7660fc_set_front_back_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable front back interrupt
uint8_t mma7660fc_set_tap_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap interrupt
uint8_t mma7660fc_set_tap_x_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap x detection
uint8_t mma7660fc_get_tap_z_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get tap z detection status
uint8_t mma7660fc_set_tap_y_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap y detection
uint8_t mma7660fc_set_auto_sleep(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable auto sleep
mma7660fc_sleep_counter_prescaler_t
mma7660fc sleep counter prescaler enumeration definition
uint8_t mma7660fc_get_tap_detection_threshold(mma7660fc_handle_t *handle, uint8_t *threshold)
get tap detection threshold
uint8_t mma7660fc_set_interrupt_active_level(mma7660fc_handle_t *handle, mma7660fc_interrupt_active_level_t level)
set interrupt active level
uint8_t mma7660fc_set_tap_pulse_debounce_count(mma7660fc_handle_t *handle, uint8_t count)
set tap pulse debounce count
mma7660fc_auto_sleep_rate_t
mma7660fc auto sleep rate enumeration definition
uint8_t mma7660fc_irq_handler(mma7660fc_handle_t *handle)
irq handler
mma7660fc_tilt_debounce_filter_t
mma7660fc tilt debounce filter enumeration definition
uint8_t mma7660fc_get_mode(mma7660fc_handle_t *handle, mma7660fc_mode_t *mode)
get mode
mma7660fc_mode_t
mma7660fc mode enumeration definition
uint8_t mma7660fc_get_interrupt_active_level(mma7660fc_handle_t *handle, mma7660fc_interrupt_active_level_t *level)
get interrupt active level
uint8_t mma7660fc_get_auto_wake_rate(mma7660fc_handle_t *handle, mma7660fc_auto_wake_rate_t *rate)
get auto wake rate
uint8_t mma7660fc_set_tap_detection_rate(mma7660fc_handle_t *handle, mma7660fc_auto_sleep_rate_t rate)
set tap detection rate
uint8_t mma7660fc_get_auto_sleep_status(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get auto sleep status
uint8_t mma7660fc_set_shake_y_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable shake y interrupt
uint8_t mma7660fc_set_sleep_count(mma7660fc_handle_t *handle, uint8_t count)
set sleep count
uint8_t mma7660fc_get_interrupt_pin_type(mma7660fc_handle_t *handle, mma7660fc_interrupt_pin_type_t *type)
get interrupt pin type
uint8_t mma7660fc_get_auto_wake_up_status(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get auto wake up status
uint8_t mma7660fc_get_tap_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get tap interrupt status
uint8_t mma7660fc_get_tap_x_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t *enable)
get tap x detection status
uint8_t mma7660fc_set_tap_z_detection(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable tap z detection
uint8_t mma7660fc_set_up_down_right_left_interrupt(mma7660fc_handle_t *handle, mma7660fc_bool_t enable)
enable or disable up down right left interrupt
mma7660fc_auto_wake_rate_t
mma7660fc auto wake rate enumeration definition
@ MMA7660FC_STATUS_AUTO_SLEEP
@ MMA7660FC_STATUS_AUTO_WAKE_UP
@ MMA7660FC_STATUS_UPDATE
uint8_t mma7660fc_set_reg(mma7660fc_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t mma7660fc_get_reg(mma7660fc_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v