コード例 #1
0
ファイル: adc.c プロジェクト: LaurentBa/libopencm3-freertos
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
{
	uint32_t reg32_1 = 0, reg32_2 = 0, reg32_3 = 0, reg32_4 = 0;
	uint8_t i = 0;

	/* Maximum sequence length is 16 channels. */
	if (length > 16) {
		return;
	}

	for (i = 1; i <= length; i++) {
		if (i <= 4) {
			reg32_1 |= (channel[i - 1] << (i * 6));
		}
		if ((i > 4) & (i <= 9)) {
			reg32_2 |= (channel[i - 1] << ((i - 4 - 1) * 6));
		}
		if ((i > 9) & (i <= 14)) {
			reg32_3 |= (channel[i - 1] << ((i - 9 - 1) * 6));
		}
		if ((i > 14) & (i <= 16)) {
			reg32_4 |= (channel[i - 1] << ((i - 14 - 1) * 6));
		}
	}
	reg32_1 |= ((length - 1) << ADC_SQR1_L_LSB);

	ADC_SQR1(adc) = reg32_1;
	ADC_SQR2(adc) = reg32_2;
	ADC_SQR3(adc) = reg32_3;
	ADC_SQR4(adc) = reg32_4;
}
コード例 #2
0
ファイル: adc_common_v1.c プロジェクト: UweBonnes/libopencm3
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
{
	uint32_t fifth6 = 0;
	uint32_t fourth6 = 0;
	uint32_t third6 = 0;
	uint32_t second6 = 0;
	uint32_t first6 = 0;
	uint8_t i = 0;

	if (length > ADC_SQR_MAX_CHANNELS_REGULAR) {
		return;
	}

	for (i = 1; i <= length; i++) {
		if (i <= 6) {
			first6 |= (channel[i - 1] << ((i - 1) * 5));
		}
		if ((i > 6) & (i <= 12)) {
			second6 |= (channel[i - 1] << ((i - 6 - 1) * 5));
		}
		if ((i > 12) & (i <= 18)) {
			third6 |= (channel[i - 1] << ((i - 12 - 1) * 5));
		}
		if ((i > 18) & (i <= 24)) {
			fourth6 |= (channel[i - 1] << ((i - 18 - 1) * 5));
		}
		if ((i > 24) & (i <= 28)) {
			fifth6 |= (channel[i - 1] << ((i - 24 - 1) * 5));
		}
	}
#if defined(ADC_SQR5)
	ADC_SQR1(adc) = fifth6 | ((length - 1) << ADC_SQR1_L_LSB);
	ADC_SQR2(adc) = fourth6;
	ADC_SQR3(adc) = third6;
	ADC_SQR4(adc) = second6;
	ADC_SQR5(adc) = first6;
#else
	ADC_SQR1(adc) = third6 | ((length - 1) << ADC_SQR1_L_LSB);
	ADC_SQR2(adc) = second6;
	ADC_SQR3(adc) = first6;
#endif
}
コード例 #3
0
ファイル: adc.c プロジェクト: cyhuang/libopencm3
void adc_set_regular_sequence(uint32_t adc, uint8_t length, uint8_t channel[])
{
    uint32_t reg32[5] = {0,0,0,0,0};
    uint8_t i = 0;

    /* Maximum sequence length is 28 channels. */
    if (length > 28)
        return;

    for (i = 0; i < length; i++)
        reg32[4 - i/6] |= (channel[i] << ((i%6)*5));

    reg32[0] |= ((length -1) << ADC_SQR1_L_LSB);

    ADC_SQR1(adc) = reg32[0];
    ADC_SQR2(adc) = reg32[1];
    ADC_SQR3(adc) = reg32[2];
    ADC_SQR4(adc) = reg32[3];
    ADC_SQR5(adc) = reg32[4];
}