页次: 1
可用的测试代码如下
//------------------------------------------------------// // ADC input test #if(0) { adc_init(); printf("adc test init OK. \n\r"); delay_s(); i = 0; while(1) { delay_s(); u32_t v1 = adc_f1c100s_read(ADC_CHANNEL_FMINL); delay_s(); u32_t v2 = adc_f1c100s_read(ADC_CHANNEL_FMINR); delay_s(); u32_t v3 = adc_f1c100s_read(ADC_CHANNEL_LINL); delay_s(); u32_t v4 = adc_f1c100s_read(ADC_CHANNEL_MIC); printf("ADC: %08X, %08X, %08X, %08X \n\r", v1,v2,v3,v4); } } #endif u32_t adc_f1c100s_read(int channel) { u32_t mixerReg = read32(ADC_BAISADDR + ADC_MIXER_CTRL) & ~(0x1f << 8); switch (channel) { case ADC_CHANNEL_FMINL: write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 12)); break; case ADC_CHANNEL_FMINR: write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 11)); break; case ADC_CHANNEL_LINL: write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 10)); break; case ADC_CHANNEL_MIC: write32(ADC_BAISADDR + ADC_MIXER_CTRL, mixerReg | (1 << 13)); break; default: // mute all break; } udelay(); // wait for internal filter to be stable // FIFO flush write32(ADC_BAISADDR + ADC_FIFOC, read32(ADC_BAISADDR + ADC_FIFOC) | (1 << 0)); while( (read32(ADC_BAISADDR + ADC_FIFOS) & (1 <<23))==0); // by default, 0V = -24000 and VRA = 0. // make 0V = 0 and vreference = 65535. int val = (read32(ADC_BAISADDR + ADC_RXDATA));// >> 16); return (u32_t)val; } void adc_init(void) { // ADC打开时钟 // write32( 0x01C20008, (read32(0x01C20008) | (1<<31)) ); write32( 0x01C20068, (read32(0x01C20068) | (1<<0)) ); write32( 0x01C20140, (read32(0x01C20140) | (1<<31)) ); udelay(); write32( 0x01C202D0, (read32(0x01C202D0) | (1<<0)) ); udelay(); //24kHz采样率 ,// digital enable // fifo mode 0 delay 0 8fifo 16bit mono u32_t regVal = (2 << 29) | (1 <<28) | (0xf << 8) | (1 << 7); write32(ADC_BAISADDR + ADC_FIFOC, regVal); // ADC enable gain 0 all mute regVal = (1 << 31) | (3<<24) | (3<<16)| (1 <<14) | (1<<7) | (1<<3) | (0 << 0); write32(ADC_BAISADDR + ADC_MIXER_CTRL, regVal); }
感谢大神,我试试下
自己改的写了 设备驱动 没有成功点亮oled
oled_probe 是否有问题
static int oled_probe(struct spi_device *spi)
{
int ret = 0;
oled_dev.spi_oled_dev = spi;
struct device *dev = &spi->dev;
ret = spi_setup(spi);
if (ret)
return ret;
oled_dev.node = dev->of_node;
if(oled_dev.node == NULL){
printk("fail_get_node\r\n");
}
oled_dev.spi_oled_dc_pin = of_get_named_gpio(oled_dev.node, "dc-gpio", 0);
if(oled_dev.spi_oled_dc_pin<0){
ret = -EINVAL;
goto fail_get_node;
}
oled_dev.spi_oled_rst_pin = of_get_named_gpio(oled_dev.node, "rst-gpio", 0);
if(oled_dev.spi_oled_rst_pin<0){
ret = -EINVAL;
goto fail_get_node;
}
printk("request gpio %d\r\n", oled_dev.spi_oled_dc_pin);
ret = gpio_direction_output(oled_dev.spi_oled_dc_pin, 0);
if(ret<0){
printk("can't gpio_direction_output gpio %d\r\n", oled_dev.spi_oled_dc_pin);
goto setout_fail;
}
ret = gpio_direction_output(oled_dev.spi_oled_rst_pin, 0);
if(ret<0){
printk("can't gpio_direction_output gpio %d\r\n", oled_dev.spi_oled_rst_pin);
goto setout_fail;
}
oled_dev.major = register_chrdev(0, "oled", &oled_ops);
oled_dev.class = class_create(THIS_MODULE, "oled");
printk("matched\r\n");
device_create(oled_dev.class, NULL, MKDEV(oled_dev.major, 0), NULL, DRIVER_NAME);
OLEDInit();
// OLED_Set_DC(0);
// OLED_Set_RST(0);
return 0;
setout_fail:
fail_get_node:
return ret;
}
&spi1 {
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins_a &oled_dc_rst_pins>;
status = "okay";
spioled@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "spioled";
spi-max-frequency = <1000000>;
dc-gpio = <&pio 4 11 GPIO_ACTIVE_HIGH>;
rst-gpio = <&pio 4 12 GPIO_ACTIVE_HIGH>;
reg = <0>;
};
};
页次: 1