Ejemplo n.º 1
0
static bool test_pwm_get_set_frequency_before_init(void)
{
    uint32_t frequency = 5000;

    return pwm_set_frequency(MIKROBUS_1, frequency) == -1
        && pwm_get_frequency(MIKROBUS_1, &frequency) == -1;
}
Ejemplo n.º 2
0
static bool test_pwm_get_set_frequency_invalid_index(void)
{
    uint32_t frequency = 5000;

    return pwm_set_frequency(3, frequency) == -1
        && pwm_get_frequency(3, &frequency) == -1;
}
Ejemplo n.º 3
0
static ssize_t pwm_period_freq_show(struct device *dev,
                                    struct device_attribute *attr,
                                    char *buf)
{
    struct pwm_device *p = dev_get_drvdata(dev);
    return sprintf(buf, "%lu\n", pwm_get_frequency(p));
}
Ejemplo n.º 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;
}
Ejemplo n.º 5
0
static bool test_pwm_set_frequency(void)
{
    uint32_t frequency = 5000;
    uint32_t tmp;
    uint32_t period;

    if (pwm_set_frequency(MIKROBUS_1, frequency) == -1)
        return false;

    if (pwm_get_frequency(MIKROBUS_1, &tmp) == -1)
        return false;

    if (abs(tmp - frequency) > 1)
        return false;

    if (pwm_get_period(MIKROBUS_1, &period) == -1)
        return false;

    tmp = 1000000000/period;
    return fabs(tmp - frequency) < 1.f;
}
Ejemplo n.º 6
0
static bool test_pwm_get_frequency_null_var(void)
{
    return pwm_get_frequency(MIKROBUS_1, NULL) == -1;
}