mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Create basic ES8388 DAC amplifier component
This commit is contained in:
		
							
								
								
									
										30
									
								
								esphome/components/es8388/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								esphome/components/es8388/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | import esphome.codegen as cg | ||||||
|  | import esphome.config_validation as cv | ||||||
|  |  | ||||||
|  | from esphome.components import i2c | ||||||
|  | from esphome.const import CONF_ID | ||||||
|  | from esphome import pins | ||||||
|  |  | ||||||
|  | es8388_ns = cg.esphome_ns.namespace("es8388") | ||||||
|  | ES8388Component = es8388_ns.class_("ES8388Component", cg.Component, i2c.I2CDevice) | ||||||
|  |  | ||||||
|  | CONF_POWER_PIN = "power_pin" | ||||||
|  |  | ||||||
|  | CONFIG_SCHEMA = ( | ||||||
|  |     cv.Schema( | ||||||
|  |         { | ||||||
|  |             cv.GenerateID(): cv.declare_id(ES8388Component), | ||||||
|  |             cv.Required(CONF_POWER_PIN): pins.gpio_output_pin_schema, | ||||||
|  |         } | ||||||
|  |     ) | ||||||
|  |     .extend(i2c.i2c_device_schema(0x10)) | ||||||
|  |     .extend(cv.COMPONENT_SCHEMA) | ||||||
|  | ) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | async def to_code(config): | ||||||
|  |     var = cg.new_Pvariable(config[CONF_ID]) | ||||||
|  |     await cg.register_component(var, config) | ||||||
|  |     await i2c.register_i2c_device(var, config) | ||||||
|  |     pin = await cg.gpio_pin_expression(config[CONF_POWER_PIN]) | ||||||
|  |     cg.add(var.set_power_pin(pin)) | ||||||
							
								
								
									
										55
									
								
								esphome/components/es8388/es8388_component.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								esphome/components/es8388/es8388_component.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | |||||||
|  | #include "es8388_component.h" | ||||||
|  |  | ||||||
|  | namespace esphome { | ||||||
|  | namespace es8388 { | ||||||
|  |  | ||||||
|  | void ES8388Component::setup() { | ||||||
|  |   this->power_pin_->setup(); | ||||||
|  |   this->power_pin_->digital_write(false); | ||||||
|  |  | ||||||
|  |   // reset | ||||||
|  |   this->write_bytes(0x00, {0x80}, 1); | ||||||
|  |   this->write_bytes(0x00, {0x00}, 1); | ||||||
|  |   // mute | ||||||
|  |   this->write_bytes(0x19, {0x04}, 1); | ||||||
|  |   this->write_bytes(0x01, {0x50}, 1); | ||||||
|  |   // powerup | ||||||
|  |   this->write_bytes(0x02, {0x00}, 1); | ||||||
|  |   // slave mode | ||||||
|  |   this->write_bytes(0x08, {0x00}, 1); | ||||||
|  |   // DAC powerdown | ||||||
|  |   this->write_bytes(0x04, {0xC0}, 1); | ||||||
|  |   // vmidsel/500k ADC/DAC idem | ||||||
|  |   this->write_bytes(0x00, {0x12}, 1); | ||||||
|  |  | ||||||
|  |   this->write_bytes(0x01, {0x00}, 1); | ||||||
|  |   // i2s 16 bits | ||||||
|  |   this->write_bytes(0x17, {0x18}, 1); | ||||||
|  |   // sample freq 256 | ||||||
|  |   this->write_bytes(0x18, {0x02}, 1); | ||||||
|  |   // LIN2/RIN2 for mixer | ||||||
|  |   this->write_bytes(0x26, {0x09}, 1); | ||||||
|  |   // left DAC to left mixer | ||||||
|  |   this->write_bytes(0x27, {0x90}, 1); | ||||||
|  |   // right DAC to right mixer | ||||||
|  |   this->write_bytes(0x2A, {0x90}, 1); | ||||||
|  |   // DACLRC ADCLRC idem | ||||||
|  |   this->write_bytes(0x2B, {0x80}, 1); | ||||||
|  |   this->write_bytes(0x2D, {0x00}, 1); | ||||||
|  |   // DAC volume max | ||||||
|  |   this->write_bytes(0x1B, {0x00}, 1); | ||||||
|  |   this->write_bytes(0x1A, {0x00}, 1); | ||||||
|  |  | ||||||
|  |   this->write_bytes(0x02, {0xF0}, 1); | ||||||
|  |   this->write_bytes(0x02, {0x00}, 1); | ||||||
|  |   this->write_bytes(0x1D, {0x1C}, 1); | ||||||
|  |   // DAC power-up LOUT1/ROUT1 enabled | ||||||
|  |   this->write_bytes(0x04, {0x30}, 1); | ||||||
|  |   // unmute | ||||||
|  |   this->write_bytes(0x19, {0x00}, 1); | ||||||
|  |  | ||||||
|  |   // Turn on amplifier | ||||||
|  |   this->power_pin_->digital_write(true); | ||||||
|  | } | ||||||
|  | }  // namespace es8388 | ||||||
|  | }  // namespace esphome | ||||||
							
								
								
									
										20
									
								
								esphome/components/es8388/es8388_component.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								esphome/components/es8388/es8388_component.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | #include "esphome/components/i2c/i2c.h" | ||||||
|  | #include "esphome/core/component.h" | ||||||
|  | #include "esphome/core/gpio.h" | ||||||
|  |  | ||||||
|  | namespace esphome { | ||||||
|  | namespace es8388 { | ||||||
|  |  | ||||||
|  | class ES8388Component : public Component, public i2c::I2CDevice { | ||||||
|  |  public: | ||||||
|  |   void setup() override; | ||||||
|  |   void set_power_pin(GPIOPin *pin) { this->power_pin_ = pin; } | ||||||
|  |  | ||||||
|  |  protected: | ||||||
|  |   GPIOPin *power_pin_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | }  // namespace es8388 | ||||||
|  | }  // namespace esphome | ||||||
		Reference in New Issue
	
	Block a user