#include <nrfx_timer.h>

#if 1

#define TIMER_ID 1
static const nrfx_timer_t timer = NRFX_TIMER_INSTANCE(TIMER_ID);

static void on_timer_event(nrf_timer_event_t evt, void *ctx) {}

void init_us_timer(void)
{

    nrfx_timer_config_t cfg = NRFX_TIMER_DEFAULT_CONFIG(1000000);
//    nrfx_timer_config_t cfg = NRFX_TIMER_DEFAULT_CONFIG(16000000);
//    cfg.frequency = NRF_TIMER_FREQ_1MHz;
    cfg.mode = NRF_TIMER_MODE_TIMER;
    cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;

uint32_t status = nrfx_timer_init(&timer, &cfg, on_timer_event);
__ASSERT_NO_MSG(status == NRFX_SUCCESS);
    nrfx_timer_enable(&timer);
}

uint32_t get_us_count(void)
{
    return nrfx_timer_capture_get(&timer, NRF_TIMER_CC_CHANNEL0);
}

uint32_t capture_us(void)
{
    nrfx_timer_capture(&timer, NRF_TIMER_CC_CHANNEL0);
    return get_us_count();
}

void clear_us(void)
{
    nrfx_timer_clear(&timer);
    return;
}
#endif
