📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)
細 文字列「__FORCETOC__」を「{{#seo: |title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki |keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 |description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This pag… |
|||
| (同じ利用者による、間の4版が非表示) | |||
| 78行目: | 78行目: | ||
* Ready | * Ready | ||
* CS Change | * CS Change | ||
<br> | |||
<u>※注意</u><br> | |||
<u>一部のSPIデバイスやドライバでは、これらの設定の一部がサポートされていない場合がある。</u><br> | |||
<u>使用する前に、ターゲットのハードウェアとドライバがこれらの設定をサポートしていることを確認すること。</u><br> | |||
<br> | <br> | ||
<syntaxhighlight lang="c++"> | <syntaxhighlight lang="c++"> | ||
| 195行目: | 199行目: | ||
ssize_t ret = read(fd, buffer.data(), buffer.size()); | ssize_t ret = read(fd, buffer.data(), buffer.size()); | ||
if (ret < 0) { | if (ret < 0) { | ||
emit errorOccurred(" | emit errorOccurred("SPIの読み込みに失敗"); | ||
break; | break; | ||
} | } | ||
| 268行目: | 272行目: | ||
<br><br> | <br><br> | ||
== | == SPI通信の送信 == | ||
以下の例では、非同期処理を使用して、SPI通信でデータを送信している。<br> | 以下の例では、非同期処理を使用して、SPI通信でデータを送信している。<br> | ||
<br> | <br> | ||
| 274行目: | 278行目: | ||
// SpiWriter.hファイル | // SpiWriter.hファイル | ||
class SpiWriter : public SpiDevice | |||
class SpiWriter : public | |||
{ | { | ||
Q_OBJECT | Q_OBJECT | ||
public: | public: | ||
using SpiDevice::SpiDevice; | |||
void writeData(const QByteArray& data) | void writeData(const QByteArray& data) | ||
| 301行目: | 295行目: | ||
int fd = spiDevice.handle(); | int fd = spiDevice.handle(); | ||
ssize_t ret = write(fd, data.constData(), data.size()); | ssize_t ret = write(fd, data.constData(), data.size()); | ||
if (ret < 0) { | if (ret < 0) { | ||
| 327行目: | 309行目: | ||
signals: | signals: | ||
void dataWritten(int bytes); | void dataWritten(int bytes); | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| 336行目: | 317行目: | ||
#include <QCoreApplication> | #include <QCoreApplication> | ||
#include <QTimer> | #include <QTimer> | ||
#include " | #include "SpiDevice.h" | ||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
| 343行目: | 324行目: | ||
SpiWriter writer("/dev/spidev0.0"); | SpiWriter writer("/dev/spidev0.0"); | ||
SpiDevice::Config config; | |||
config.mode = SpiDevice::Mode::Mode0; | |||
config.lsbFirst = true; | |||
config.threeWire = true; | |||
config.loopback = false; | |||
config.noCs = true; | |||
config.ready = false; | |||
config.csChange = false; | |||
config.bitsPerWord = 8; | |||
config.speed = 1000000; | |||
QObject::connect(&writer, &SpiWriter::dataWritten, [](int bytes) { | QObject::connect(&writer, &SpiWriter::dataWritten, [](int bytes) { | ||
| 351行目: | 343行目: | ||
qDebug() << "エラーが発生: " << error; | qDebug() << "エラーが発生: " << error; | ||
}); | }); | ||
QTimer::singleShot(5000, [&writer]() { | QTimer::singleShot(5000, [&writer]() { | ||
writer.writeData(QByteArray::fromHex("0102030405")); | writer.writeData(QByteArray::fromHex("0102030405")); | ||
| 361行目: | 353行目: | ||
<br><br> | <br><br> | ||
{{#seo: | |||
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki | |||
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 | |||
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux | |||
|image=/resources/assets/MochiuLogo_Single_Blue.png | |||
}} | |||
__FORCETOC__ | __FORCETOC__ | ||
[[カテゴリ:Qt]] | [[カテゴリ:Qt]] | ||