コード例 #1
0
static bool test_pwm_get_set_duty_cycle_before_init(void)
{
    float duty_cycle = 50.f;

    return pwm_set_duty_cycle(MIKROBUS_1, duty_cycle) == -1
        && pwm_get_duty_cycle(MIKROBUS_1, &duty_cycle) == -1;
}
コード例 #2
0
static bool test_pwm_get_set_duty_cycle_invalid_index(void)
{
    float duty_cycle = 5000.f;

    return pwm_set_duty_cycle(3, duty_cycle) == -1
        && pwm_get_duty_cycle(3, &duty_cycle) == -1;
}
コード例 #3
0
static unsigned ev3_output_port_get_duty_cycle(void *context)
{
	struct ev3_output_port_data *data = context;
	unsigned period = pwm_get_period(data->pwm);

	if (unlikely(period == 0))
		return 0;
	return pwm_get_duty_cycle(data->pwm) * 100 / period;
}
コード例 #4
0
static bool test_pwm_init(void)
{
    float duty_cycle_1, duty_cycle_2;
    uint32_t freq_1, freq_2;

    if (pwm_init(MIKROBUS_1) == -1
    ||  pwm_init(MIKROBUS_1) == -1
    ||  pwm_init(MIKROBUS_2) == -1
    ||  pwm_init(MIKROBUS_1) == -1)
        return false;

    if (pwm_get_duty_cycle(MIKROBUS_1, &duty_cycle_1) == -1
    ||  pwm_get_duty_cycle(MIKROBUS_2, &duty_cycle_2) == -1)
        return false;

    if (fabs(duty_cycle_1 - 50.f) > 0.1f) {
        printf("duty_cycle on mikrobus 1 is %f%% instead of 50%%\n", duty_cycle_1);
        return false;
    }
    if (fabs(duty_cycle_2 - 50.f) > 0.1f) {
        printf("duty_cycle on mikrobus 2 is %f%% instead of 50%%\n", duty_cycle_2);
        return false;
    }

    if (pwm_get_frequency(MIKROBUS_1, &freq_1) == -1
    ||  pwm_get_frequency(MIKROBUS_2, &freq_2) == -1)
        return false;

    if (abs(freq_1 - 3000) > 1) {
        printf("frequency on mikrobus 1 is %uHz instead of 3kHz\n", freq_1);
        return false;
    }
    if (abs(freq_2 - 3000) > 1) {
        printf("frequency on mikrobus 2 is %uHz instead of 3kHz\n", freq_1);
        return false;
    }

    return true;
}
コード例 #5
0
static bool test_pwm_get_duty_cycle_null_var(void)
{
    return pwm_get_duty_cycle(MIKROBUS_1, NULL) == -1;
}