From: asterix Date: Thu, 14 Jul 2011 17:20:58 +0000 (+0000) Subject: Define wm8731 context, add log. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=0c3aff9d12e6c2b45c85f2e4f0639b6acb1fab16;p=bertos.git Define wm8731 context, add log. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4969 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_wm8731.h b/bertos/cfg/cfg_wm8731.h index 046446f3..aa938f4a 100644 --- a/bertos/cfg/cfg_wm8731.h +++ b/bertos/cfg/cfg_wm8731.h @@ -38,6 +38,19 @@ #ifndef CFG_WM8731_H #define CFG_WM8731_H +/** + * Module logging level. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define WM8731_LOG_LEVEL LOG_LVL_INFO + +/** + * Module logging format. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define WM8731_LOG_FORMAT LOG_FMT_TERSE #endif /* CFG_WM8731_H */ diff --git a/bertos/drv/wm8731.c b/bertos/drv/wm8731.c index 2ce98314..e55e55ed 100644 --- a/bertos/drv/wm8731.c +++ b/bertos/drv/wm8731.c @@ -39,6 +39,11 @@ #include "hw/hw_wm8731.h" #include "cfg/cfg_wm8731.h" +// Define logging setting (for cfg/log.h module). +#define LOG_LEVEL WM8731_LOG_LEVEL +#define LOG_FORMAT WM8731_LOG_FORMAT +#include + #include #include @@ -144,25 +149,24 @@ -static void wm8731_write(uint8_t reg, uint16_t value) +static void wm8731_write(Wm8731 *ctx, uint8_t reg, uint16_t value) { - uint16_t tmp = ((reg & 0x7f) << 9) | (value & 0x1ff); - uint8_t msb = (tmp & 0xFF00) >> 8; - uint8_t lsb = tmp & 0xFF; + uint16_t tmp = ((reg & 0x7F) << 9) | (value & 0x1FF); - kprintf("msb: %0x lsb: %0x\n", msb, lsb); -/* - i2c_start_w(&i2c, CODEC_ADDR, 2, I2C_STOP); - i2c_putc(&i2c, msb); - i2c_putc(&i2c, lsb); + i2c_start_w(ctx->i2c, CODEC_ADDR, 2, I2C_STOP); + i2c_putc(ctx->i2c, (uint8_t)((tmp & 0xFF00) >> 8)); + i2c_putc(ctx->i2c, (uint8_t)(tmp & 0xFF)); + if (i2c_error(ctx->i2c)) + LOG_ERR("Error while send command to codec.\n"); - if (i2c_error(&i2c)) - kputs("Errore!\n"); -*/ } -void wm8731_init(void) +void wm8731_init(Wm8731 *ctx, I2c *i2c); { + ctx->i2c = i2c; + + WM8731_PIN_INIT(); + WM8731_MCLK_INIT(); } diff --git a/bertos/drv/wm8731.h b/bertos/drv/wm8731.h index 54e5ca9c..78269dcf 100644 --- a/bertos/drv/wm8731.h +++ b/bertos/drv/wm8731.h @@ -43,6 +43,13 @@ #ifndef DRV_WM8731_H #define DRV_WM8731_H -void wm8731_init(void); +#include + +typedef struct Wm8731 +{ + I2c *i2c; +} Wm8731; + +void wm8731_init(Wm8731 *ctx, I2c *i2c); #endif /* DRV_WM8731_H */