ctr_mcu/branches/2.15_yamaha_taisaku/i2c_mcu-sub.c
n2232 941ab03888 yamaha codec 対応
ROMあふれのため、i2c_mcuのうち、一部(自己アップデートに不要)なのを違うセグメントへ ほんの数バイト!

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@431 013db118-44a6-b54f-8bf7-843cb86687b1
2011-12-19 07:08:24 +00:00

109 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ========================================================
簡易I2C内蔵ペリフェラル使用通信
de JHL 藤田@開技
'09 Feb -
$Id$
======================================================== */
#ifndef _WIN32
#pragma sfr
#pragma di
#pragma ei
#pragma nop
#pragma inline // memcpy()をインライン展開する(の方が小さい!)
#endif
#include "incs.h"
#include "i2c_mcu.h"
#include "loader.h"
#include "util_funcs.h"
#include "i2c_mcu_sub.h"
#include "pm.h" /// やりたくなかった…CODECのレジスタ名をひくため
// ========================================================
// ワークアラウンド用
static void iic_mcu_simple_dummy_write();
static i2c_err iic_mcu_codec_write_low( u8 adrs, u8 dat );
// i2c_mcu.c にいる
extern void iic_mcu_send_re_st( );
extern void iic_mcu_send_sp( );
extern i2c_err iic_mcu_send_a_byte( u8 );
extern i2c_err iic_mcu_call_slave( u8 slave );
/********************************************//**
コーデックに 『1バイト』 ライト
iic_mcu_write_a_byte CODEC不具合ワークアラウンド
***********************************************/
i2c_err iic_mcu_write_a_byte_codec( u8 adrs, u8 dat )
{
u8 pm_reg_original;
u8 rv;
// ヤマハcodecワークアラウンド SPIとの共用レジスタの中身を取得
if(( rv = iic_mcu_read( IIC_SLA_CODEC, CODEC_REG_PM, 1, &pm_reg_original )) != I2C_ERR_OK )
{
return( rv );
}
// phase1 ここまで
// 書き込み!
if( ( rv = iic_mcu_codec_write_low( adrs, dat ) ) != I2C_ERR_OK )
{
return( rv );
}
// ヤマハcodecワークアラウンド phase2
{
// 共有レジスタが 0x00 なら書き戻す
u8 pm_reg_after;
if(( rv = iic_mcu_read( IIC_SLA_CODEC, CODEC_REG_PM, 1, &pm_reg_after )) != I2C_ERR_OK )
{
return( rv );
}
if( pm_reg_after != 0x00 )
{
return( I2C_ERR_OK );
}
// else {
return iic_mcu_codec_write_low( CODEC_REG_PM, pm_reg_original );
// リトライなどは無し
}
return( I2C_ERR_OK );
}
static i2c_err iic_mcu_codec_write_low( u8 adrs, u8 dat )
{
IICMK10 = 1; // DMA用のISRに飛ばさないためにマスク
if( iic_mcu_call_slave( IIC_SLA_CODEC ) != I2C_ERR_OK )
{
iic_mcu_busy = false;
return ( I2C_ERR_NOSLAVE );
}
iic_mcu_send_a_byte( adrs );
iic_mcu_send_a_byte( dat );
// TIワークアラウンド
// re-stでダミーライト
{
iic_mcu_send_re_st( );
iic_mcu_send_a_byte( IIC_SLA_CODEC ); // ダミーライト
iic_mcu_send_a_byte( 0x20 ); // ゴミを書いても問題ないアドレス
iic_mcu_send_a_byte( 0xAA ); // 何でもよい
}
iic_mcu_send_sp( );
iic_mcu_busy = false;
return( I2C_ERR_OK );
}