Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-10-20 22:24:46 +08:00
commit 6d880fcada
11 changed files with 828 additions and 827 deletions

View File

@ -0,0 +1,64 @@
[#]: collector: (lujun9972)
[#]: translator: (chenmu-kk)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-12735-1.html)
[#]: subject: (NFC vs. Bluetooth LE: When to use which)
[#]: via: (https://www.networkworld.com/article/3574932/nfc-vs-bluetooth-le-when-to-use-which.html)
[#]: author: (Jon Gold https://www.networkworld.com/author/Jon-Gold/)
近场通信 vs. 低功耗蓝牙:如何抉择
======
> 近场通信NFC和低功耗蓝牙BLE是适合企业不同用途的低功耗无线技术。
![](https://images.idgesg.net/images/article/2020/08/distributed_network_of_wifi_wi-fi_internet_connections_across_cityscape_by_metamorworks_gettyimages-926502948_2400x1600-100855926-large.jpg)
在低功率、相对短距离连接的众多选择中有两种技术脱颖而出——近场通信NFC和低功耗蓝牙BLE。两者都具有相对低廉的部署成本且易于使用。
NFC 作为许多现代智能卡片的背后技术而为大众所熟知。NFC 芯片必须十分接近(在几厘米内)读卡器来实现连接,但这是它主要企业用例(安全性和访问控制)的一个优势。
BLE 是主要蓝牙标准的低功耗衍生品,以较低的潜在吞吐量换来了能耗的显著降低,从而能够适应更广泛的潜在用例。
接下来,我们将对每种技术及其主要用例进行更深入的描述。
### NFC 的未来
NFC 在近距离接触范围内工作(设备间必须靠近到几厘米范围内来进行连接),一个可读的无源 NFC “标签”根本不需要任何独立电源,它会从读卡器的信号中汲取能量,工作频率约为 13.5MHz,在主动读取芯片时需要 100-700µA 的电量。
“短距离实际上是它的优势。”Gartner 研究高级总监兼分析师说, “NFC 的一大优点是它不仅仅是无线电,还内置了一个庞大的安全协议。”也就是说,潜在的不良行为者必须非常接近——使用专用设备、在几米的范围内——才能检测到正在发生的 NFC 连接。NFC 还可以施行在 SSL 技术上面一层以提高安全性。
考虑到 NFC 本就起源于非接触式支付技术,这不足为奇。它在这一领域的根基在于对零售商的吸引力,零售商可以利用 NFC 让客户在购买商品前获取相关的信息、获得优惠券或者向店员寻求帮助,只需将手机接触到 NFC 热点即可。
尽管 NFC 只能在一个很近的范围内使用,这限制了使用 NFC 技术用例场景但它不仅仅是为了开门和买一杯拿铁。NFC 可以用于引导连接,便于设备间轻松快速的配对,因此用户只需在会议室中将手机贴近配备好的投影仪,即可创建一个 NFC 连接,并验证智能手机是否是一个可连接的授权设备,并进行演示。演示文稿或者视频数据本身不会通过 NFC 来传输,但是 NFC 握手可作为另外的无线协议(例如 Wi-Fi 网络或者任何其他更高带宽可以传输数据的网络)间的验证,从而无需用户登录。
### BLE 的特点
相较之下BLE 的工作距离要远的多(长达几十米),其最大带宽 1 Mbit/s 约为 NFC 连接的两倍。它是著名的蓝牙技术的产物,相较于主线标准的更低功耗,它为机器到机器的连接做了优化。在连接两端的耗电量均小于 15 mA实用范围约为 10米可通过 AES 加密保护连接。
然而,根据 Forrester 首席分析师 Andre Kindness 的说法,它远非 NFC 的替代品。
他说:“从信息传递角度来看, [NFC] 比 BLE 快得多。”BLE 通常需要几分之一秒或更长时间的验证并安全连接,而 NFC 几乎在瞬间完成连接。
不过,根据 IDC 高级研究分析师 Patrick Filkins 的说法,相较于 NFCBLE 由于范围更广而有着更多的通用性。
他说:“我认为 BLE 比较适合企业”。而类似于资产追踪、室内导航和目标广告的用例只是冰山一角。
对于企业结果是相当直接的——NFC 用例大多与公司使用蓝牙的用例是分开的对于少有的可以选择的重叠相对的优势和劣势显而易见。NFC 距离很短、价格便宜、可即时连接以及数据转换率较低。BLE 的工作距离更远、传输速率更高,成本也更高,连接时还需要一点时间来进行“握手”。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3574932/nfc-vs-bluetooth-le-when-to-use-which.html
作者:[Jon Gold][a]
选题:[lujun9972][b]
译者:[chenmu-kk](https://github.com/chenmu-kk)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Jon-Gold/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/newsletters/signup.html
[2]: https://www.facebook.com/NetworkWorld/
[3]: https://www.linkedin.com/company/network-world

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: ( chenmu-kk )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,133 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux Jargon Buster: What is FOSS (Free and Open Source Software)? What is Open Source?)
[#]: via: (https://itsfoss.com/what-is-foss/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Linux Jargon Buster: What is FOSS (Free and Open Source Software)? What is Open Source?
======
What does FOSS in Its FOSS mean? What is FOSS?
I have been asked this question numerous time in the past. It was about time that I explained what is FOSS in Linux and the software world.
The distinction is important because FOSS is a generic world and it could mean different depending on the context. Here, I am discussing the FOSS principle in software.
### What is FOSS?
FOSS means Free and Open Source Software. It doesnt mean software is free of cost. It means that source code of the software is open for all and anyone is free to use, study and modify the code. This principle allows other people to contribute to the development and improvement of a software like a community.
#### The origin of FOSS
In the 60s and 70s, computers were hardware focused and the hardware were expensive. They were mainly used by academics in universities or researchers in labs. The limited amount of software used to come for free or with their source code and the users were allowed to modify the source code to suit their need.
In the late 70s and early 80s, the manufacturers stopped distributing source code in an attempt to not let their software run on their competitors computers.
This restrictive licensing led to the inconvenience and dislike of peoplewho were used to and fond of modifying software. In the mid 80s, Richard Stallman started the Free Software Movement.
[Stallman specified four essential fundamental freedom][1] for a software to be Free and Open Source Software.
![Free Software Freedoms][2]
I am rephrasing them for easier understanding:
* Any user should be able to run the software for any purpose.
* User should be free to see the source code of the software and if need be, user should be allowed to modify the code as well.
* User should be free to distribute the copies of the software to others.
* If a user modified the code, she/he should be free to distribute the modified code to others. The modified code must have the source code open.
If interested, I would advise reading this article on the [history of FOSS][3].
### Free in Free and Open Source Software DOES NOT mean free of cost
![][4]
As you may have noticed, the free in Free and Open Source Software doesnt mean it is free of cost. It means freedom to run, modify and distribute the software.
People often wrongly think that FOSS or Open Source software cannot have a price tag. This is not correct.
Most Free and Open Source Software are available free of cost because of a number of reasons:
* The source code is already available to public so some developers see no point in putting a price tag on the downloads.
* Some projects are contributed by a number of volunteers for free. So, the main developer(s) find it unethical to charge for something that has been contributed freely by so many people.
* Some projects are supported and/or developed by bigger corporate or non-profit organizations who employ developers to work on their open source projects.
* Some developers create open source projects as hobby or out of their passion for contributing to the world with their code. Things like number of downloads, contributions and words of appreciations matter more than money for them.
To avoid the emphasis on free some people use the term FLOSS. FLOSS stands for Free and Libre Open Source Software. The world libre (meaning freedom) is different than gartuit/gratis (free of cost).
> Free as in free speech, not free as in free beer.
### How do FOSS projects make money?
It is a myth that open source projects dont make money. Red Hat was the first open source company to reach the billion dollars mark. [IBM bought Red Hat for $34 billion][5]. There are many such examples.
Many open source projects, specially the ones in the enterprise sectors, offer support and enterprise oriented features for a fee. This is main business model for Red Hat, SUSE Linux and more such projects.
Some open source projects like Discourse, WordPress offer hosted instance of their software for a premium fee.
Many open source projects, specially the desktop applications, rely on donations. VLC, GIMP, Inkscape and other such open source software fell in this category. There are [ways to fund open-source programs][6] but usually, youll find donation links on project websites.
Making money with open source software may be difficult but it is not entirely impossible.
### But I am not a programmer. Why should I care if a software is open source or not?
This is a valid question. You are not a software developer, just a regular computer user. Even if the source code of the software is available, you wont understand how the program works.
Thats fine. You wont understand it but someone with the necessary skill sets will and thats what matter.
Think of this way. Perhaps you wont understand a complicated legal document. But if you have the freedom to look at the document and keep a copy of it, you can consult someone who can check the document for legal pitfalls.
In other words, open source software has transparency.
### What is the difference between FOSS and Open Source?
![][7]
Youll often come across terms FOSS and open source. They are often used interchangeably.
Are they the same thing? It is difficult to answer in yes and no.
You see, the term free in FOSS is confusing for many as people incorrectly assume that it as free of cost. Enterprise executives, higher ups and decision makers tend to focus on free in Free and Open Source. Since they are business people focused on making money for their company, the term free works as deterrence in adopting the FOSS principles.
This is why a new organization named [Open Source Initiative][8] was created in the mid 90s. They removed the Free from Free and Open Source Software and created their own [definition of open source][9]. and their own set of licenses.
The term open source got quite popular specially in the software industry. The executives are more comfortable with Open Source. The adoption of open source grew rapidly and I believe removal of free term did play a role here.
**Got questions?**
This As I explained in the article [what is Linux Distribution][10], the FOSS/open source concept played a big role in the development and popularity of Linux.
I tried to explain the concept of FOSS and open source in simpler terms in this jargon buster article. I have tried to avoid going too much in detail or technical accuracies.
I do hope you have a better understanding of this topic now. If you have got questions or suggestions, feel free to leave a comment and continue the discussion there.
--------------------------------------------------------------------------------
via: https://itsfoss.com/what-is-foss/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.gnu.org/philosophy/free-sw.html
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/09/foss-freedoms.jpg?resize=800%2C671&ssl=1
[3]: https://itsfoss.com/history-of-foss/
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/09/think-free-speech-not-free-beer.jpg?resize=800%2C800&ssl=1
[5]: https://itsfoss.com/ibm-red-hat-acquisition/
[6]: https://itsfoss.com/open-source-funding-platforms/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/09/what-is-foss.png?resize=800%2C450&ssl=1
[8]: https://opensource.org/
[9]: https://opensource.org/osd
[10]: https://itsfoss.com/what-is-linux-distribution/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (gxlct008)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,430 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (gxlct008)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Go on very small hardware (Part 3))
[#]: via: (https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html)
[#]: author: (Michał Derkacz )
Go on very small hardware (Part 3)
======
[![STM32F030F4P6][1]][2]
Most of the examples discussed in the [first][3] and [second][4] part of this series are blinking LEDs in one or another way. It may have been interesting at first, but after a while it has become a bit boring. Lets do something more entertaining…
…lets light more LEDs!
### WS281x LEDs
The [WS281x][5] RGB LEDs (and their clones) are very popular. You can buy them as single elements, chained into long strips or assembled into matrices, rings or other form-factors.
![WS2812B][6]
They can be connected in series and thanks to this fact, you can control a long LED strip with only single pin of your MCU. Unfortunately, the phisical protocol used by their internal controller doesnt fit straight into any peripheral you can find in a MCU. You have to use bit-banging or use available peripherals in unusual way.
Which of the available solutions is the most efficient depends on the number of LED strips controlled at the same time. If you have to drive 4 to 16 strips the most efficient way is to [use timers and DMA][7] (dont overlook the links at the end of Martins article).
If you have to control only one or two strips, use the available SPI or UART peripherals. In case of SPI you can encode only two WS281x bits in one byte sent. UART allows more dense coding thanks to clever use of the start and stop bits: 3 bits per one byte sent.
The best explanation of how the UART protocol fits into WS281x protocol I found on [this site][8]. If you dont know Polish, here is the [English translation][9].
The WS281x based LEDs are still the most popular but there are also SPI controlled LEDs on the market: [APA102][10], [SK9822][11]. Three interesting articles about them: [1][12], [2][13], [3][14].
### LED ring
There are many WS2812 based rings on the marker. I have this one:
![WS2812B][15]
It has 24 individually addressable RGB LEDs (WS2812B) and exposes four terminals: GND, 5V, DI and DO. You can chain more rings or other WS2812 based things by connecting DI (data in) terminal to the DO (data out) terminal of the previous one.
Lets connect this ring to our STM32F030 board. We will use the UART based driver so the DI should be connected to the TXD pin on the UART header. The WS2812B LED requires a power supply with at least 3.5V. 24 LEDs can consume quite a lot of current, so during the programming/debuggin its best to connect the GND and 5V terminals on the ring directly to the GND and 5V pins available on ST-LINK programmer:
![WS2812B][16]
Our STM32F030F4P6 MCU and the whole STM32 F0, F3, F7, L4 families have one important thing that the F1, F4, L1 MCUs dont have: it allows to invert the UART signals and therefore we can connect the ring directly to the UART TXD pin. If you dont known that we need such inversion you probably didnt read the [article][9] I mentioned above.
So you cant use the popular [Blue Pill][17] or the [STM32F4-DISCOVERY][18] this way. Use their SPI peripheral or an external inverter. See the [Christmas Tree Lights][19] project as an example of UART+inverter or the [WS2812 example][20] for NUCLEO-F411RE that uses SPI.
By the way, probably the most of DISCOVERY boards have one more problem: they work with VDD = 3V instead of 3.3V. The WS281x requires at least the supply voltage * 0.7 for DI high. This is 3.5V in case of 5V supply and 3.3V in case of 4.7V you can find on the 5V pins of the DISCOVERY. As you can see, even in our case the first LED works 0.2V below spec. In case of DISCOVERY it will work 0.3V bellow spec if powered 4.7V and 0.5V bellow spec if powered 5V.
Lets finish this lengthy introduction and go to the code:
```
package main
import (
"delay"
"math/rand"
"rtos"
"led"
"led/ws281x/wsuart"
"stm32/hal/dma"
"stm32/hal/gpio"
"stm32/hal/irq"
"stm32/hal/system"
"stm32/hal/system/timer/systick"
"stm32/hal/usart"
)
var tts *usart.Driver
func init() {
system.SetupPLL(8, 1, 48/8)
systick.Setup(2e6)
gpio.A.EnableClock(true)
tx := gpio.A.Pin(9)
tx.Setup(&gpio.Config{Mode: gpio.Alt})
tx.SetAltFunc(gpio.USART1_AF1)
d := dma.DMA1
d.EnableClock(true)
tts = usart.NewDriver(usart.USART1, d.Channel(2, 0), nil, nil)
tts.Periph().EnableClock(true)
tts.Periph().SetBaudRate(3000000000 / 1390)
tts.Periph().SetConf2(usart.TxInv)
tts.Periph().Enable()
tts.EnableTx()
rtos.IRQ(irq.USART1).Enable()
rtos.IRQ(irq.DMA1_Channel2_3).Enable()
}
func main() {
var rnd rand.XorShift64
rnd.Seed(1)
rgb := wsuart.GRB
strip := wsuart.Make(24)
black := rgb.Pixel(0)
for {
c := led.Color(rnd.Uint32()).Scale(127)
pixel := rgb.Pixel(c)
for i := range strip {
strip[i] = pixel
tts.Write(strip.Bytes())
delay.Millisec(40)
}
for i := range strip {
strip[i] = black
tts.Write(strip.Bytes())
delay.Millisec(20)
}
}
}
func ttsISR() {
tts.ISR()
}
func ttsDMAISR() {
tts.TxDMAISR()
}
//c:__attribute__((section(".ISRs")))
var ISRs = [...]func(){
irq.USART1: ttsISR,
irq.DMA1_Channel2_3: ttsDMAISR,
}
```
##### The import section
The new things in the import section compared to the previous examples are the rand/math package and led package with its led/ws281x subtree. The led package itself contains definition of Color type. The led/ws281x/wsuart defines the ColorOrder, Pixel and Strip types.
I was wondering about using the Color or RGBA type from image/color and about defining the Strip in the way that it will implement image.Image interface but because of using a [gamma correction][21] and the big overhead of image/draw package I ended with simple:
```
type Color uint32
type Strip []Pixel
```
with a few useful methods. However, this can change in the future.
##### The init function
There arent so much novelties in the init function. The UART baud rate was changed from 115200 to 3000000000/1390 ≈ 2158273 which corresponds to 1390 nanoseconds per WS2812 bit. The TxInv bit in CR2 register is set to invert TXD signal.
##### The main function
The XorShift64 pseudorandom number generator is used to generate random colors. [XORSHIFT][22] is currently the only algorithm implemented by math/rand package. You have to explicitly initialize it using its Seed method with nonzero argument.
The rgb variable is of type wsuart.ColorOrder and is set to the GRB color order used by WS2812 (WS2811 uses RGB order). Its then used to translate colors to pixels.
The `wsuart.Make(24)` creates initialized strip of 24 pixels. It is equivalent of:
```
strip := make(wsuart.Strip, 24)
strip.Clear()
```
The rest of the code uses random colors to draw something similar to “Please Wait…” spinner.
The strip slice acts as a framebuffer. The `tts.Write(strip.Bytes())` sends the content of the framebuffer to the ring.
##### Interrupts
The program is ened with the code that handles interrupts, the same as in the previous [UART example][23].
Lets compile it and run:
```
$ egc
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
14088 240 204 14532 38c4 cortexm0.elf
$ openocd -d0 -f interface/stlink.cfg -f target/stm32f0x.cfg -c 'init; program cortexm0.elf; reset run; exit'
```
Ive skipped the openocd output. The video bellow shows how this program works:
Sorry, your browser doesn't support embedded videos.
### Lets do something useful…
At the beginning of the [first part][3] Ive asked: “How low we can Go and still do something useful?”. Our MCU is actually a low-end device (8-bitters will probably disagree with me) but we havent done anything useful so far.
So… Lets do something useful… Lets make a Clock!
There are many examples of clocks built of RGB LEDs on the Internet. Lets make our own using our little board and RGB ring. We change the previous code as described below.
##### The import section
Remove the math/rand package and add stm32/hal/exti.
##### Global variables
Add two new global variables: btn and btnev:
```
var (
tts *usart.Driver
btn gpio.Pin
btnev rtos.EventFlag
)
```
They will be used to handle the “button” that will be used to set our clock. Our board has no button except reset, but somehow we can manage without it.
##### The init function
Add this code to the init function:
```
btn = gpio.A.Pin(4)
btn.Setup(&gpio.Config{Mode: gpio.In, Pull: gpio.PullUp})
ei := exti.Lines(btn.Mask())
ei.Connect(btn.Port())
ei.EnableFallTrig()
ei.EnableRiseTrig()
ei.EnableIRQ()
rtos.IRQ(irq.EXTI4_15).Enable()
```
The PA4 pin is configured as input with the internal pull-up resistor enabled. Its connected to the onboard LED but that doesnt hinder anything. More important is that its located next to the GND pin so we can use any metal object to simulate the button and set the clock. As a bonus we have additional feedback from the onboard LED.
We use the EXTI peripheral to track the PA4 state. Its configured to generate an interrupt on any change.
##### The btnWait function
Define a new auxiliary function:
```
func btnWait(state int, deadline int64) bool {
for btn.Load() != state {
if !btnev.Wait(1, deadline) {
return false // timeout
}
btnev.Reset(0)
}
delay.Millisec(50) // debouncing
return true
}
```
It waits for the specified state on the “button” pin, but only until the deadline occurs. This is slightly improved polling code:
```
for btn.Load() != state {
if rtos.Nanosec() >= deadline {
// timeout
}
}
```
Our btnWait function, instead of busy waiting for state or deadline, uses the btnev variable of type rtos.EventFlag to sleep until something will happen. You can of course use a channel instead of rtos.EventFlag but the latter one is much cheaper.
##### The main function
We need completly new main function:
```
func main() {
rgb := wsuart.GRB
strip := wsuart.Make(24)
ds := 4 * 60 / len(strip) // Interval between LEDs (quarter-seconds).
adjust := 0
adjspeed := ds
for {
qs := int(rtos.Nanosec() / 25e7) // Quarter-seconds since reset.
qa := qs + adjust
qa %= 12 * 3600 * 4 // Quarter-seconds since 0:00 or 12:00.
hi := len(strip) * qa / (12 * 3600 * 4)
qa %= 3600 * 4 // Quarter-seconds in the current hour.
mi := len(strip) * qa / (3600 * 4)
qa %= 60 * 4 // Quarter-seconds in the current minute.
si := len(strip) * qa / (60 * 4)
hc := led.Color(0x550000)
mc := led.Color(0x005500)
sc := led.Color(0x000055)
// Blend the colors if the hands of the clock overlap.
if hi == mi {
hc |= mc
mc = hc
}
if mi == si {
mc |= sc
sc = mc
}
if si == hi {
sc |= hc
hc = sc
}
// Draw the clock and write to the ring.
strip.Clear()
strip[hi] = rgb.Pixel(hc)
strip[mi] = rgb.Pixel(mc)
strip[si] = rgb.Pixel(sc)
tts.Write(strip.Bytes())
// Sleep until the button pressed or the second hand should be moved.
if btnWait(0, int64(qs+ds)*25e7) {
adjust += adjspeed
// Sleep until the button is released or timeout.
if !btnWait(1, rtos.Nanosec()+100e6) {
if adjspeed < 5*60*4 {
adjspeed += 2 * ds
}
continue
}
adjspeed = ds
}
}
}
```
We use the rtos.Nanosec function instead of time.Now to obtain the current time. This saves much of Flash but also reduces our clock to antique device that has no idea about days, months and years and worst of all it doesnt handle daylight saving changes.
Our ring has 24 LEDs, so the second hand can be presented with the accuracy of 2.5s. To dont sacrifice this accuracy and get smooth operation we use quarter-second as base interval. Half-second would be enough but quarter-second is more accurate and works also well with 16 and 48 LEDs.
The red, green and blue colors are used respectively for hour, minute and second hands. This allows us to use simple logical or operation for color blending. We have the Color.Blend method that can blend arbitrary colors but were low of Flash so we prefer simplest possible solution.
We redraw the clock only when the second hand moved. The:
```
btnWait(0, int64(qs+ds)*25e7)
```
is waiting for exactly that moment or for the press of the button.
Every press of the button adjust the clock forward. There is an acceleration when the button is held down for some time.
##### Interrupts
Define new interrupt handler:
```
func exti4_15ISR() {
pending := exti.Pending() & 0xFFF0
pending.ClearPending()
if pending&exti.Lines(btn.Mask()) != 0 {
btnev.Signal(1)
}
}
```
and add `irq.EXTI4_15: exti4_15ISR,` entry to the ISRs array.
This handler (or Interrupt Service Routine) handles EXTI4_15 IRQ. The Cortex-M0 CPU supports significantly fewer IRQs than its bigger brothers, so you can often see that one IRQ is shared by multiple interrupt sources. In our case one IRQ is shared by 12 EXTI lines.
The exti4_15ISR reads all pending bits and selects 12 more significant of them. Next it clears the seleced bits in EXTI and starts to handle them. In our case only bit 4 is checked. The `btnev.Signal(1)` causes that the `btnev.Wait(1, deadline)` wakes up and returns true.
You can find the complete code on [Github][24]. Lets compile it:
```
$ egc
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
15960 240 216 16416 4020 cortexm0.elf
```
There are only 184 bytes for any iprovements. Lets rebuild everything one more time but this time without any type and field names in typeinfo:
```
$ cd $HOME/emgo
$ ./clean.sh
$ cd $HOME/firstemgo
$ egc -nf -nt
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
15120 240 216 15576 3cd8 cortexm0.elf
```
Now, with a kilobyte of free space you can improve something. Lets see how it works:
Sorry, your browser doesn't support embedded videos.
I dont know how I managed to hit exactly 3:00 !?
Thats all Folks! In the part 4 (ending this series) well try to display something on a LCD.
--------------------------------------------------------------------------------
via: https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html
作者:[-;Michał Derkacz][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://ziutek.github.io
[b]: https://github.com/lujun9972
[1]: https://ziutek.github.io/images/mcu/f030-demo-board/board.jpg
[2]: https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html
[3]: https://ziutek.github.io/2018/03/30/go_on_very_small_hardware.html
[4]: https://ziutek.github.io/2018/04/14/go_on_very_small_hardware2.html
[5]: http://www.world-semi.com/solution/list-4-1.html
[6]: https://ziutek.github.io/images/led/ws2812b.jpg
[7]: http://www.martinhubacek.cz/arm/improved-stm32-ws2812b-library
[8]: http://mikrokontrolery.blogspot.com/2011/03/Diody-WS2812B-sterowanie-XMega-cz-2.html
[9]: https://translate.google.pl/translate?sl=pl&tl=en&u=http://mikrokontrolery.blogspot.com/2011/03/Diody-WS2812B-sterowanie-XMega-cz-2.html
[10]: http://neon-world.com/en/product.php
[11]: http://www.normandled.com/index.php/Product/view/id/800.html
[12]: https://cpldcpu.wordpress.com/2014/08/27/apa102/
[13]: https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/
[14]: https://cpldcpu.wordpress.com/2016/12/13/sk9822-a-clone-of-the-apa102/
[15]: https://ziutek.github.io/images/led/rgbring.jpg
[16]: https://ziutek.github.io/images/led/ring-stlink-f030.jpg
[17]: https://jeelabs.org/article/1649a/
[18]: http://www.st.com/en/evaluation-tools/stm32f4discovery.html
[19]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/minidev/treelights
[20]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/nucleo-f411re/ws2812
[21]: https://en.wikipedia.org/wiki/Gamma_correction
[22]: https://en.wikipedia.org/wiki/Xorshift
[23]: https://ziutek.github.io/2018/04/14/go_on_very_small_hardware2.html#uart
[24]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/f030-demo-board/ws2812-clock

View File

@ -1,192 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (2 Ways to Download Files From Linux Terminal)
[#]: via: (https://itsfoss.com/download-files-from-linux-terminal/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
2 Ways to Download Files From Linux Terminal
======
If you are stuck to the Linux terminal, say on a server, how do you download a file from the terminal?
There is no download command in Linux but there are a couple of Linux commands for downloading file.
In this terminal trick, youll learn two ways to download file using command line in Linux.
I am using Ubuntu here but apart from the installation, rest of the commands are equally valid for all other Linux distributions.
### Download files from Linux terminal using wget command
![][1]
[wget][2] is perhaps the most used command line download manager for Linux and UNIX-like systems. You can download a single file, multiple files, entire directory or even an entire website using wget.
wget is non-interactive and can easily work in the background. This means you can easily use it in scripts or even build tools like [uGet download manager][3].
Lets see how to use wget to download file from terminal.
#### Installing wget
Most Linux distributions come with wget preinstalled. It is also available in the repository of most distributions and you can easily install it using your distributions package manager.
On Ubuntu and Debian based distribution, you can use the [apt package manager][4] command:
```
sudo apt install wget
```
#### Download a file or webpage using wget
You just need to provide the URL of the file or webpage. It will download the file with its original name in the directory you are in.
```
wget URL
```
![][5]
To download multiple files, youll have to save their URLs in a text file and provide that text file as input to wget like this:
```
wget -i download_files.txt
```
#### Download files with a different name using wget
Youll notice that a webpage is almost always saved as index.html with wget. It will be a good idea to provide custom name to downloaded file.
You can use the -O (uppercase O) option to provide the output filename while downloading.
```
wget -O filename URL
```
![][6]
#### Download a folder using wget
Suppose you are browsing an FTP server and you need to download an entire directory, you can use the recursive option
```
wget -r ftp://server-address.com/directory
```
#### Download an entire website using wget
Yes, you can totally do that. You can mirror an entire website with wget. By downloading an entire website I mean the entire public facing website structure.
While you can use the mirror option -m directly, it will be a good idea add:
* convert-links : links are converted so that internal links are pointed to downloaded resource instead of web
* page-requisites: downloads additional things like style sheets so that the pages look better offline
```
wget -m --convert-links --page-requisites website_address
```
![][7]
#### Bonus Tip: Resume incomplete downloads
If you aborted the download by pressing C for some reasons, you can resume the previous download with option -c.
```
wget -c
```
### Download files from Linux command line using curl
Like wget, [curl][8] is also one of the most popular commands to download files in Linux terminal. There are so many ways to [use curl extensively][9] but Ill focus on only the simple downloading here.
#### Installing curl
Though curl doesnt come preinstalled, it is available in the official repositories of most distributions. You can use your distributions package manager to install it.
To [install curl on Ubuntu][10] and other Debian based distributions, use the following command:
```
sudo apt install curl
```
#### Download files or webpage using curl
If you use curl without any option with a URL, it will read the file and print it on the terminal screen.
To download a file using curl command in Linux terminal, youll have to use the -O (uppercase O) option:
```
curl -O URL
```
![][11]
It is simpler to download multiple files in Linux with curl. You just have to specify multiple URLs:
```
curl -O URL1 URL2 URL3
```
Keep in mind that curl is not as simple as wget. While wget saves webpages as index.html, curl will complain of remote file not having a name for webpages. Youll have to save it with a custom name as described in the next section.
#### Download files with a different name
It could be confusing but to provide a custom name for the downloaded file (instead of the original source name), youll have to use -o (lowercase O) option:
```
curl -o filename URL
```
![][12]
Some times, curl wouldnt just download the file as you expect it to. Youll have to use option -L (for location) to download it correctly. This is because some times the links redirect to some other link and with option -L, it follows the final link.
#### Pause and resume download with curl
Like wget, you can also resume a paused download using curl with option -c:
```
curl -c URL
```
**Conclusion**
As always, there are multiple ways to do the same thing in Linux. Downloading files from the terminal is no different.
wget and curl are just two of the most popular commands for downloading files in Linux. There are more such command line tools. Terminal based web-browsers like [elinks][13], [w3m][14] etc can also be used for downloading files in command line.
Personally, for a simple download, I prefer using wget over curl. It is simpler and less confusing because you may have a difficult time figuring out why curl could not download a file in the expected format.
Your feedback and suggestions are welcome.
--------------------------------------------------------------------------------
via: https://itsfoss.com/download-files-from-linux-terminal/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/Download-Files-from-Linux-terminal.png?resize=800%2C450&ssl=1
[2]: https://www.gnu.org/software/wget/
[3]: https://itsfoss.com/install-latest-uget-ubuntu-linux-mint/
[4]: https://itsfoss.com/apt-command-guide/
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-file-in-linux-terminal-using-wget.png?resize=795%2C418&ssl=1
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-file-in-linux-terminal-using-wget-2.png?resize=795%2C418&ssl=1
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-entire-website-using-wget.png?resize=795%2C418&ssl=1
[8]: https://curl.haxx.se/
[9]: https://linuxhandbook.com/curl-command-examples/
[10]: https://itsfoss.com/install-curl-ubuntu/
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-files-in-linux-using-curl.png?resize=795%2C418&ssl=1
[12]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-files-in-linux-using-curl-1.png?resize=795%2C418&ssl=1
[13]: http://elinks.or.cz/
[14]: http://w3m.sourceforge.net/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,69 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( chenmu-kk )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (NFC vs. Bluetooth LE: When to use which)
[#]: via: (https://www.networkworld.com/article/3574932/nfc-vs-bluetooth-le-when-to-use-which.html)
[#]: author: (Jon Gold https://www.networkworld.com/author/Jon-Gold/)
NFC vs. 蓝牙 LE: 如何抉择
======
近场通信和蓝牙LE是适合企业不同用途的低功耗无线技术。
Metamorworks / Getty Images
在低功率、相对短距离连接的众多选择中,两种技术脱颖而出——近场通信和低功耗蓝牙。两者都具有相对低廉的部署成本且易于使用。
NFC作为许多现代智能卡片的背后技术而为大众所熟知。NFC芯片必须十分接近在几厘米内读卡器来实现连接 但这是它主要企业用例(安全性和访问控制)的一个优势。
[[通过注册Network World时事通讯定期获取信息。]][1]
蓝牙LE是主要蓝牙标准的低功耗衍生产品通过显著降低能耗来抵消较低的潜在吞吐量并具备适应更宽广的潜在用例的能力。
接下来,我们将研究每种技术更深入的细节内容以及它们的主要用例。
### NFC的未来
NFC在近距离接触范围内工作设备间必须靠近到几厘米范围内来进行连接一个可读无源的NFC芯片根本不需要任何独立电源它会从读卡器的信号中汲取能量工作频率在13.5MHz附近并且在主动读取芯片时需要100-700µA的电源。
Gartner研究高级总监兼分析师说“事实上短距离是它的优势。” NFC的一大优点是它不仅仅是无线电还内置了庞大的安全协议。也就是说潜在的不良因素将会逼近——使用专用设备在几米的范围内才能检测到正在发生的NFC连接。 NFC的施行还可以在SSL技术上分层来提高安全性。
考虑到NFC本就起源于非接触式支付技术这不足为奇。它的根源在于对零售商的吸引力它可以使用NFC让客户在购买商品、获取优惠券或者向店员寻求帮助前通过简单地使用手机来连接NFC热点就可以获取相关的信息。
尽管NFC只能在一个很短的范围内使用限制了使用NFC技术用例的数量但它不仅仅是打开门买一杯拿铁。NFC用于引导连接便于设备间轻松快速的配对因此用户可以在配备有投影仪的会议室中使用手机即可创建一个NFC连接并验证智能手机是否是一个可连接的授权设备并显示相关的信息。演示文稿或者视频数据本身不会通过NFC来传输但是NFC握手可作为不同无线协议间的验证从而无需用户登录例如Wi-Fi网络或者任何其他更高带宽可以传输数据的网络。
### 蓝牙LE的特点
相较之下Bluetooth LE可以在更长的距离上运行长达几十米在1 Mbit / s的带宽下其最大带宽约为NFC连接的两倍。它是出名的蓝牙技术的产物相较于主线标准的更低功耗优化了双机连接。 在双机连接的任何一端电流均小于15 mA实用范围约为10米可通过AES加密保护连接。
根据Forrester首席分析师Andre Kindness的说法它远非NFC的替代品。
他说:“从信息传递角度来看, [NFC] 比BLE快一点。”BLE通常需要一秒或更长时间的验证并安全连接而NFC几乎在瞬间完成连接。
然而根据IDC高级研究分析师Patrick Filkins的说法相较于NFC蓝牙LE由于范围更广而有着更多的通用性。
他说“我认为蓝牙LE比较适合企业”。而类似于资产追踪室内导航和目标广告的用例只是冰山一角。
对于企业结果是相当直接的——NFC用例大多与公司使用蓝牙的用例是分开的对于少有的可以选择的重叠相对的优势和劣势显而易见。NFC有着短距离廉价即时连接以及更低数据转换率的优点。蓝牙LE工作的距离更远、传输速率更高成本也更高还需要一点时间来进行“握手”连接。
加入 [Facebook][2] 和 [LinkedIn][3] 上的Network World社区在最热门的话题下留下你的评论。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3574932/nfc-vs-bluetooth-le-when-to-use-which.html
作者:[Jon Gold][a]
选题:[lujun9972][b]
译者:[chenmu-kk](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Jon-Gold/
[b]: https://github.com/lujun9972
[1]: https://www.networkworld.com/newsletters/signup.html
[2]: https://www.facebook.com/NetworkWorld/
[3]: https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,129 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux Jargon Buster: What is FOSS \(Free and Open Source Software\)? What is Open Source?)
[#]: via: (https://itsfoss.com/what-is-foss/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
Linux 黑话解释:什么是 FOSS自由和开源软件什么是开源
======
![][7]
什么是 FOSS
在过去,我曾多次被问到这个问题,现在是时候解释一下什么是 Linux 和软件世界中的 FOSS 了。
这个区别很重要,因为 FOSS 是一个通用的词汇,它可以根据上下文的不同而有不同的含义。在这里,我讨论的是软件中的 FOSS 原则。
### 什么是 FOSS
FOSS 是指<ruby>自由和开放源码软件<rt>Free and Open Source Software</rt></ruby>。这并不意味着软件是免费的。它意味着软件的源代码是开放的,任何人都可以自由使用、研究和修改代码。这个原则允许人们像一个社区一样为软件的开发和改进做出贡献。
#### FOSS 的起源
在上世纪 60、70 年代,计算机以硬件为主,硬件价格昂贵。它们主要由大学的学者或实验室的研究人员使用。以前有限的软件都是免费的,或者是带有它们的源代码,用户可以根据自己的需要修改源代码。
在上世纪 70 年代末和 80 年代初,制造商为了不让自己的软件在竞争对手的计算机上运行,停止了分发源代码。
这种限制性的许可导致了那些习惯和喜欢修改软件的人的不便和不喜。上世纪 80 年代中期Richard Stallman 发起了<ruby>自由软件运动<rt>Free Software Movement</rt></ruby>
[Stallman 指明了一个软件要成为 FOSS 的四个基本自由][1]。
![自由软件自由][2]
为了便于理解,我将它们重新表述:
* 任何用户应能为任何目的运行软件。
* 用户应能自由查看软件的源代码,如有需要,应允许用户修改代码。
* 用户应能自由地将软件的副本分发给他人。
* 如果用户修改了代码,她/他应该可以自由地将修改后的代码发布给他人。修改后的代码必须开放源代码。
如果有兴趣,我建议阅读这篇关于 [FOSS 的历史][3]的文章。
### FOSS 中的 “Free” 并不意味着免费
![][4]
你可能已经注意到了,自由和开源软件中的 “Free” 并不意味着它是免费的,它意味着运行、修改和分发软件的自由。
人们经常错误地认为FOSS 或开源软件不能有价格标签。这是不正确的。
大多数 FOSS 都是免费提供的,原因有很多:
* 源代码已经向公众开放,所以一些开发者认为没有必要在下载上贴上价格标签。
* 有些项目是由一些志愿者免费提供的。因此,主要的开发者认为对这么多人免费贡献的东西收费是不道德的。
* 有些项目是由较大的企业或非营利组织支持和/或开发的,这些组织会雇佣开发人员在他们的开源项目上工作。
* 有些开发者创建开源项目是出于兴趣,或者出于他们对用代码为世界做贡献的热情。对他们来说,下载量、贡献和感谢的话比金钱更重要。
为了避免强调 “免费”,有些人使用了 FLOSS 这个词。FLOSS 是<ruby>自由和开源软件<rt>Free/Libre Open Source Software</rt></ruby>的缩写。单词 Libre意为自由与 gartuit/gratis免费不同。
> “Free”是言论自由的自由而不是如免费啤酒的免费。
### FOSS 项目如何赚钱?
开源项目不赚钱是一个神话。红帽是第一个达到 10 亿美元大关的开源公司。[IBM 以 340 亿美元收购了红帽][5]。这样的例子有很多。
许多开源项目特别是企业领域的项目都会提供收费的支持和面向企业的功能。这是R红帽、SUSE Linux 和更多此类项目的主要商业模式。
一些开源项目,如 Discourse、WordPress 等,则提供其软件的托管实例,并收取一定的费用。
许多开源项目特别是桌面应用程序依靠捐赠。VLC、GIMP、Inkscape 等这类开源软件就属于这一类。有[资助开源项目的方法][6],但通常,你会在项目网站上找到捐赠链接。
利用开源软件赚钱可能很难,但也不是完全不可能。
### 但我不是程序员,我为什么要关心一个软件是否开源?
这是一个合理的问题。你不是一个软件开发者,只是一个普通的计算机用户。即使软件的源代码是可用的,你也不会理解程序的工作原理。
这很好。你不会明白,但有必要技能的人就会明白,这才是最重要的。
你可以这样想。也许你不会理解一份复杂的法律文件。但如果你有看文件的自由,并保留一份副本,你就可以咨询某个人,他可以检查文件中的法律陷阱。
换句话说,开源软件具有透明度。
### FOSS 与开源之间的区别是什么?
你会经常遇到 FOSS 和开源的术语。它们经常被互换使用。
它们是同一件事吗?这很难用“是”和“不是”来回答。
你看FOSS 中的“Free”一词让很多人感到困惑因为人们错误地认为它是免费的。企业高管、高层和决策者往往会关注自由和开源中的“免费”。由于他们是商业人士专注于为他们的公司赚钱“自由”一词在采用 FOSS 原则时起到了威慑作用。
这就是为什么在上世纪 90 年代中期创建出了一个名为<ruby>[开源促进会][8]<rt>Open Source Initiative</rt></ruby>的新组织。他们从自由和开放源码软件中去掉了“自由”一词,并创建了自己的[开放源码的定义][9],以及自己的一套许可证。
<ruby>开源<rt>Open Source</rt></ruby>”一词在软件行业特别流行。高管们对开源更加适应。开源软件的采用迅速增长,我相信 “免费”一词的删除确实起到了作用。
### 有问题吗?
这正如我在[什么是 Linux 发行版][10]一文中所解释的那样FOSS/开源的概念在 Linux 的发展和普及中起到了很大的作用。
我试图在这篇黑话解释文章中用更简单的语言解释 FOSS 和开源的概念,而试图避免在细节或技术精度上做过多的阐述。
我希望你现在对这个话题有了更好的理解。如果你有问题或建议,欢迎留言并继续讨论。
--------------------------------------------------------------------------------
via: https://itsfoss.com/what-is-foss/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://www.gnu.org/philosophy/free-sw.html
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/09/foss-freedoms.jpg?resize=800%2C671&ssl=1
[3]: https://itsfoss.com/history-of-foss/
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/09/think-free-speech-not-free-beer.jpg?resize=800%2C800&ssl=1
[5]: https://itsfoss.com/ibm-red-hat-acquisition/
[6]: https://itsfoss.com/open-source-funding-platforms/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/09/what-is-foss.png?resize=800%2C450&ssl=1
[8]: https://opensource.org/
[9]: https://opensource.org/osd
[10]: https://itsfoss.com/what-is-linux-distribution/

View File

@ -0,0 +1,440 @@
[#]: collector: (lujun9972)
[#]: translator: (gxlct008)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Go on very small hardware Part 3)
[#]: via: (https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html)
[#]: author: (Michał Derkacz )
Go 语言在极小硬件上的运用(三)
======
[![STM32F030F4P6][1]][2]
在本系列的 [第一][3] 和 [第二][4] 部分中讨论的大多数示例都是以一种或另一种方式闪烁的 LED。起初它可能很有趣但是一段时间后变得有些无聊。让我们做些更有趣的事情……
…让我们点亮更多的 LED
### WS281x LEDs
[WS281x][5] RGB LED及其克隆非常受欢迎。您可以作为单个元素购买、链成长条或组装成矩阵、环或其他形状因子。
![WS2812B][6]
它们可以串联连接,基于这个事实,您可以只用 MCU 的单个引脚就可以控制一个很长的 LED 灯条。不幸的是,它们的内部控制器使用的物理协议不能直接适用于您在 MCU 中可以找到的任何外围设备。您必须使用 <ruby>位脉冲<rt>bit-banging</rt></ruby>或以特殊方式使用可用的外设。
哪种可用的解决方案最有效取决于同时控制的 LED 灯条数量。如果您必须驱动 4 到 16 个条带,那么最有效的方法是 [使用定时器和 DMA][7](请不要忽略 Martin 文章末尾的链接)。
如果只需要控制一个或两个条带,请使用可用的 SPI 或 UART 外设。对于 SPI您只能在发送的一个字节中编码两个 WS281x 位。由于巧妙地使用了起始位和停止位UART 允许更密集的编码:每发送一个字节 3 位。
我在 [此站点][8] 上找到了有关 UART 协议如何适用于 WS281x 协议的最佳解释。如果您不懂波兰语,这里是 [英文翻译][9]。
基于 WS281x 的 LED 仍然是最受欢迎的,但市场上也有 SPI 控制的 LED[APA102][10][SK9822][11]。关于它们的三篇有趣的文章在这里:[1][12][2][13][3][14]
### LED 环
市场上有许多基于 WS2812 的环。我有一个这样的:
![WS2812B][15]
它具有 24 个可单独寻址的 RGB LEDWS2812B并暴露出四个端子GND、5V、DI 和 DO。通过将 DI数据输入端子连接到上一个的 DO数据输出端子可以链接更多的环或其他基于 WS2812 的东西。
让我们将这个环连接到我们的 STM32F030 板上。我们将使用基于 UART 的驱动程序,因此 DI 应连接到 UART 接头连接器上的 TXD 引脚。 WS2812B LED 需要至少 3.5V 的电源。 24 个 LED 会消耗大量电流,因此在编程/调试期间,最好将环上的 GND 和 5V 端子直接连接到 ST-LINK 编程器上可用的 GND 和 5V 引脚:
![WS2812B][16]
我们的 STM32F030F4P6 MCU 和整个 STM32 F0、F3、F7、L4 系列具有 F1、F4、L1 MCU 不具备的一项重要功能:它可以反转 UART 信号,因此我们可以将环直接连接到 UART TXD 引脚。如果您不知道我们需要这种反转,那么您可能没有读过我上面提到的 [文章][9]。
因此,您不能以这种方式使用流行的 [Blue Pill][17] 或 [STM32F4-DISCOVERY][18]。使用其 SPI 外设或外部反相器。有关使用 SPI 的 NUCLEO-F411RE请参见 [圣诞树灯][19] 项目作为 UART + 逆变器的示例或 [WS2812示例][20]。
顺便说一下,大多数 DISCOVERY 板可能还有一个问题:它们在 VDD = 3V 而不是 3.3V 的情况下工作。 对于高 DIWS281x 至少要求电源电压 * 0.7。如果是 5V 电源,则为 3.5V;如果是 4.7V 电源,则为 3.3V;可在 DISCOVERY 的 5V 引脚上找到。如您所见,即使在我们的情况下,第一个 LED 的工作电压也低于规格 0.2V。对于 DISCOVERY 板,如果供电 4.7V,它将工作在低于规格的 0.3V 下;如果供电 5V它将工作在低于规格 0.5V 下。
让我们结束这段冗长的介绍并转到代码:
```
package main
import (
"delay"
"math/rand"
"rtos"
"led"
"led/ws281x/wsuart"
"stm32/hal/dma"
"stm32/hal/gpio"
"stm32/hal/irq"
"stm32/hal/system"
"stm32/hal/system/timer/systick"
"stm32/hal/usart"
)
var tts *usart.Driver
func init() {
system.SetupPLL(8, 1, 48/8)
systick.Setup(2e6)
gpio.A.EnableClock(true)
tx := gpio.A.Pin(9)
tx.Setup(&gpio.Config{Mode: gpio.Alt})
tx.SetAltFunc(gpio.USART1_AF1)
d := dma.DMA1
d.EnableClock(true)
tts = usart.NewDriver(usart.USART1, d.Channel(2, 0), nil, nil)
tts.Periph().EnableClock(true)
tts.Periph().SetBaudRate(3000000000 / 1390)
tts.Periph().SetConf2(usart.TxInv)
tts.Periph().Enable()
tts.EnableTx()
rtos.IRQ(irq.USART1).Enable()
rtos.IRQ(irq.DMA1_Channel2_3).Enable()
}
func main() {
var rnd rand.XorShift64
rnd.Seed(1)
rgb := wsuart.GRB
strip := wsuart.Make(24)
black := rgb.Pixel(0)
for {
c := led.Color(rnd.Uint32()).Scale(127)
pixel := rgb.Pixel(c)
for i := range strip {
strip[i] = pixel
tts.Write(strip.Bytes())
delay.Millisec(40)
}
for i := range strip {
strip[i] = black
tts.Write(strip.Bytes())
delay.Millisec(20)
}
}
}
func ttsISR() {
tts.ISR()
}
func ttsDMAISR() {
tts.TxDMAISR()
}
//c:__attribute__((section(".ISRs")))
var ISRs = [...]func(){
irq.USART1: ttsISR,
irq.DMA1_Channel2_3: ttsDMAISR,
}
```
##### 导入部分
与前面的示例相比,导入部分中的新内容是 `rand/math` 包和带有 `led/ws281x` 子树的 led 包。 led 包本身包含 `Color` 类型的定义。 `led/ws281x/wsuart` 定义了 `ColorOrder`、`Pixel` 和 `Strip` 类型。
我想知道如何使用 `image/color` 中的 `Color``RGBA` 类型,以及如何以它将实现 `image.Image` 接口的方式定义 `Strip`。 但是由于使用了 [gamma 校正][21] 和 大开销的 `color/draw` 包,我以简单的方式结束:
```
type Color uint32
type Strip []Pixel
```
使用一些有用的方法。然而,这种情况在未来可能会改变。
##### init 函数
`init` 函数没有太多新颖之处。 UART 波特率从 115200 更改为 3000000000/1390 ≈ 2158273相当于每个 WS2812 位 1390 纳秒。 CR2 寄存器中的 TxInv 位设置为反转 TXD 信号。
##### main 函数
`XorShift64` 伪随机数生成器用于生成随机颜色。 [XORSHIFT][22] 是目前由 `math/rand` 包实现的唯一算法。您必须使用带有非零参数的 `Seed` 方法显式初始化它。
`rgb` 变量的类型为 `wsuart.ColorOrder`,并设置为 WS2812 使用的 GRB 颜色顺序WS2811 使用 RGB 顺序)。然后用于将颜色转换为像素。
`wsuart.Make(24)` 创建 24 像素的初始化条带。它等效于:
```
strip := make(wsuart.Strip, 24)
strip.Clear()
```
其余代码使用随机颜色绘制类似于 “Please Wait…” 微调器的内容。
条带切片充当帧缓冲区。 `tts.Write(strip.Bytes()` 将帧缓冲区的内容发送到环。
##### 中断
该程序由处理中断的代码组成,与先前的 [UART 示例][23] 中的代码相同。
让我们编译并运行:
```
$ egc
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
14088 240 204 14532 38c4 cortexm0.elf
$ openocd -d0 -f interface/stlink.cfg -f target/stm32f0x.cfg -c 'init; program cortexm0.elf; reset run; exit'
```
我跳过了 openocd 输出。下面的视频显示了该程序的工作原理:
原文中插入视频的代码:
<video width="576" height="324" controls="" preload="auto">
<source src="https://ziutek.github.io/videos/rgbspinner.mp4" type="video/mp4">
Sorry, your browser doesn't support embedded videos.
</video>
### 让我们做些有用的事情...
在 [第一部分][3] 的开头,我曾问过:“我们能降到多低,还能做一些有用的事情?”。 我们的 MCU 实际上是一种低端设备8 比特的人可能会不同意我的看法),但到目前为止,我们还没有做任何有用的事情。
所以... 让我们做些有用的事情... 让我们做个时钟!
在互联网上有许多由 RGB LED 构成的时钟示例。让我们用小板子和 RGB 环制作自己的时钟。我们按照下面的描述更改先前的代码。
##### 导入部分
删除 `math/rand` 包,然后添加 `stm32/hal/exti`
##### 全局变量
添加两个新的全局变量:`btn` 和 `btnev`
```
var (
tts *usart.Driver
btn gpio.Pin
btnev rtos.EventFlag
)
```
它们将用来处理那些用于设置时钟的 “button”。我们的板子除了重置之外没有其他按钮但是如果没有它我们仍然可以通过某种方式进行管理。
##### init 函数
将这段代码添加到 `init` 函数:
```
btn = gpio.A.Pin(4)
btn.Setup(&gpio.Config{Mode: gpio.In, Pull: gpio.PullUp})
ei := exti.Lines(btn.Mask())
ei.Connect(btn.Port())
ei.EnableFallTrig()
ei.EnableRiseTrig()
ei.EnableIRQ()
rtos.IRQ(irq.EXTI4_15).Enable()
```
在内部<ruby>上拉电阻<rt>pull-up resistor</rt></ruby>启用的情况下,将 PA4 引脚配置为输入。它已连接至板载 LED但这不会妨碍任何事情。更重要的是它位于 GND 引脚旁边,所以我们可以使用任何金属物体来模拟按钮并设置时钟。作为奖励,我们还有来自板载 LED 的其他反馈。
我们使用 EXTI 外设来跟踪 PA4 状态。它被配置为在发生任何更改时都会产生中断。
##### btnWait 函数
定义一个新的辅助功能:
```
func btnWait(state int, deadline int64) bool {
for btn.Load() != state {
if !btnev.Wait(1, deadline) {
return false // timeout
}
btnev.Reset(0)
}
delay.Millisec(50) // debouncing
return true
}
```
它等待 “button” 引脚上的指定状态,但只等到最后期限出现。这是稍微改进的轮询代码:
```
for btn.Load() != state {
if rtos.Nanosec() >= deadline {
// timeout
}
}
```
我们的 `btnWait` 函数不是忙于等待状态或截止日期,而是使用 `rtos.EventFlag` 类型的 `btnev` 变量休眠,直到有事情发生。您当然可以使用通道而不是 `rtos.EventFlag`,但是后者便宜得多。
##### main 函数
我们需要全新的 `main` 函数:
```
func main() {
rgb := wsuart.GRB
strip := wsuart.Make(24)
ds := 4 * 60 / len(strip) // Interval between LEDs (quarter-seconds).
adjust := 0
adjspeed := ds
for {
qs := int(rtos.Nanosec() / 25e7) // Quarter-seconds since reset.
qa := qs + adjust
qa %= 12 * 3600 * 4 // Quarter-seconds since 0:00 or 12:00.
hi := len(strip) * qa / (12 * 3600 * 4)
qa %= 3600 * 4 // Quarter-seconds in the current hour.
mi := len(strip) * qa / (3600 * 4)
qa %= 60 * 4 // Quarter-seconds in the current minute.
si := len(strip) * qa / (60 * 4)
hc := led.Color(0x550000)
mc := led.Color(0x005500)
sc := led.Color(0x000055)
// Blend the colors if the hands of the clock overlap.
if hi == mi {
hc |= mc
mc = hc
}
if mi == si {
mc |= sc
sc = mc
}
if si == hi {
sc |= hc
hc = sc
}
// Draw the clock and write to the ring.
strip.Clear()
strip[hi] = rgb.Pixel(hc)
strip[mi] = rgb.Pixel(mc)
strip[si] = rgb.Pixel(sc)
tts.Write(strip.Bytes())
// Sleep until the button pressed or the second hand should be moved.
if btnWait(0, int64(qs+ds)*25e7) {
adjust += adjspeed
// Sleep until the button is released or timeout.
if !btnWait(1, rtos.Nanosec()+100e6) {
if adjspeed < 5*60*4 {
adjspeed += 2 * ds
}
continue
}
adjspeed = ds
}
}
}
```
我们使用 `rtos.Nanosec` 函数代替 `time.Now` 来获取当前时间。这样可以节省大量的 Flash但也使我们的时钟变成了不知道日、月、年的老式设备最糟糕的是它无法处理夏令时的变化。
我们的环有 24 个 LED因此秒针的显示精度可以达到 2.5 秒。为了不牺牲这种精度并获得流畅的运行效果,我们使用 1/4 秒作为基准间隔。半秒就足够了,但四分之一秒更准确,而且与 16 和 48 个 LED 配合使用也很好。
红色、绿色和蓝色分别用于时针、分针和秒针。这允许我们使用简单的 `逻辑或操作` 进行颜色混合。我们 `Color.Blend` 方法可以混合任意颜色,但是我们缺少 Flash所以我们选择最简单的解决方案。
我们只有在秒针移动时才重画时钟。
```
btnWait(0, int64(qs+ds)*25e7)
```
上面的这行代码等待的正是那一刻,或者是按钮的按下。
每按一下按钮就会把时钟向前调一调。按住按钮一段时间会产生加速度。
##### 中断
定义新的中断处理程序:
```
func exti4_15ISR() {
pending := exti.Pending() & 0xFFF0
pending.ClearPending()
if pending&exti.Lines(btn.Mask()) != 0 {
btnev.Signal(1)
}
}
```
并将 `irq.EXTI4_15: exti4_15ISR` 条目添加到 ISR 数组。
该处理程序(或中断服务程序)处理 EXTI4_15 IRQ。 Cortex-M0 CPU 支持的 IRQ 明显少于其较大的同类兄弟处理器,因此您经常可以看到一个 IRQ 被多个中断源共享。在我们的例子中,一个 IRQ 由 12 个 EXTI 线共享。
exti4_15ISR 读取所有挂起的位,并从中选择 12 个更高的有效位。接下来,它清除 EXTI 中选中的位并开始处理它们。在我们的例子中,仅检查第 4 位。 `btnev.Signal(1)` 引发 `btnev.Wait(1, deadline)` 唤醒并返回 true。
您可以在 [Github][24] 上找到完整的代码。让我们来编译它:
```
$ egc
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
15960 240 216 16416 4020 cortexm0.elf
```
这里所有的改进只有 184 个字节。让我们再次重新构建所有内容,但这次在 typeinfo 中不使用任何类型和字段名:
```
$ cd $HOME/emgo
$ ./clean.sh
$ cd $HOME/firstemgo
$ egc -nf -nt
$ arm-none-eabi-size cortexm0.elf
text data bss dec hex filename
15120 240 216 15576 3cd8 cortexm0.elf
```
现在,有了千字节的空闲空间,您可以改进一些东西。让我们看看它是如何工作的:
原文中插入视频的代码:
<video width="576" height="324" controls="" preload="auto">
<source src="https://ziutek.github.io/videos/rgbclock.mp4" type="video/mp4">
Sorry, your browser doesn't support embedded videos.
</video>
我不知道我是怎么精确打到 3:00 的!?
以上就是所有内容!在第 4 部分(本系列的结束)中,我们将尝试在 LCD 上显示一些内容。
--------------------------------------------------------------------------------
via: https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html
作者:[-;Michał Derkacz][a]
选题:[lujun9972][b]
译者:[gxlct008](https://github.com/gxlct008)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://ziutek.github.io
[b]: https://github.com/lujun9972
[1]: https://ziutek.github.io/images/mcu/f030-demo-board/board.jpg
[2]: https://ziutek.github.io/2018/05/03/go_on_very_small_hardware3.html
[3]: https://ziutek.github.io/2018/03/30/go_on_very_small_hardware.html
[4]: https://ziutek.github.io/2018/04/14/go_on_very_small_hardware2.html
[5]: http://www.world-semi.com/solution/list-4-1.html
[6]: https://ziutek.github.io/images/led/ws2812b.jpg
[7]: http://www.martinhubacek.cz/arm/improved-stm32-ws2812b-library
[8]: http://mikrokontrolery.blogspot.com/2011/03/Diody-WS2812B-sterowanie-XMega-cz-2.html
[9]: https://translate.google.pl/translate?sl=pl&tl=en&u=http://mikrokontrolery.blogspot.com/2011/03/Diody-WS2812B-sterowanie-XMega-cz-2.html
[10]: http://neon-world.com/en/product.php
[11]: http://www.normandled.com/index.php/Product/view/id/800.html
[12]: https://cpldcpu.wordpress.com/2014/08/27/apa102/
[13]: https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/
[14]: https://cpldcpu.wordpress.com/2016/12/13/sk9822-a-clone-of-the-apa102/
[15]: https://ziutek.github.io/images/led/rgbring.jpg
[16]: https://ziutek.github.io/images/led/ring-stlink-f030.jpg
[17]: https://jeelabs.org/article/1649a/
[18]: http://www.st.com/en/evaluation-tools/stm32f4discovery.html
[19]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/minidev/treelights
[20]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/nucleo-f411re/ws2812
[21]: https://en.wikipedia.org/wiki/Gamma_correction
[22]: https://en.wikipedia.org/wiki/Xorshift
[23]: https://ziutek.github.io/2018/04/14/go_on_very_small_hardware2.html#uart
[24]: https://github.com/ziutek/emgo/tree/master/egpath/src/stm32/examples/f030-demo-board/ws2812-clock

View File

@ -0,0 +1,192 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (2 Ways to Download Files From Linux Terminal)
[#]: via: (https://itsfoss.com/download-files-from-linux-terminal/)
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
2 种从 Linux 终端下载文件的方法
======
如果你被困在 Linux 终端,比如说在服务器上,如何从终端下载文件?
在 Linux 中是没有下载命令的,但是有几个 Linux 命令可用于下载文件。
在这篇终端技巧中,你将学习两种在 Linux 中使用命令行下载文件的方法。
我在这里使用的是 Ubuntu但除了安装其余的命令同样适用于所有其他 Linux 发行版。
### 使用 wget 命令从 Linux 终端下载文件
![][1]
[wget][2] 也许是 Linux 和类 UNIX 系统中使用最多的命令行下载管理器。你可以使用 wget 下载一个文件、多个文件、整个目录甚至整个网站。
wget 是非交互式的,可以轻松地在后台工作。这意味着你可以很容易地在脚本中使用它,甚至构建像 [uGet 下载管理器][3]这样的工具。
让我们看看如何使用 wget 从终端下载文件。
#### 安装 wget
大多数 Linux 发行版都预装了 wget。它也可以在大多数发行版的仓库中找到你可以使用发行版的包管理器轻松安装它。
在基于 Ubuntu 和 Debian 的发行版上,你可以使用 [apt 包管理器][4]命令:
```
sudo apt install wget
```
#### 使用 wget 下载文件或网页
你只需要提供文件或网页的 URL。它将在你所在的目录下以原始名下载该文件。
```
wget URL
```
![][5]
要下载多个文件,你必须将它们的 URL 保存在一个文本文件中,并将该文件作为输入提供给 wget就像这样
```
wget -i download_files.txt
```
#### 用 wget 下载不同名字的文件
你会注意到,一个网页在 wget 中几乎总是以 index.html 的形式保存。为下载的文件提供自定义名称是个好主意。
你可以在下载时使用 -O (大写字母 O 选项来提供输出文件名。
```
wget -O filename URL
```
![][6]
#### 用 wget 下载一个文件夹
假设你正在浏览一个 FTP 服务器,你需要下载整个目录,你可以使用递归选项:
```
wget -r ftp://server-address.com/directory
```
#### 使用 wget 下载整个网站
是的,你完全可以做到这一点。你可以用 wget 镜像整个网站。我说的下载整个网站是指整个面向公众的网站结构。
虽然你可以直接使用镜像选项 -m但最好加上
* convert-links :链接将被转换,使内部链接指向下载的资源,而不是网站。
* page-requisites下载额外的东西如样式表使页面在离线状态下看起来更好。
```
wget -m --convert-links --page-requisites website_address
```
![][7]
#### 额外提示:恢复未完成的下载
如果你因为某些原因按 C 键中止了下载,你可以用选项 -c 恢复之前的下载:
```
wget -c
```
### 使用 curl 在 Linux 命令行中下载文件
和 wget 一样,[curl][8] 也是 Linux 终端中最常用的下载文件的命令之一。[使用 curl][9] 的方法有很多,但我在这里只关注简单的下载。
#### 安装 curl
虽然 curl 并不是预装的,但在大多数发行版的官方仓库中都有。你可以使用你的发行版的包管理器来安装它。
要[在 Ubuntu][10] 和其他基于 Debian 的发行版上安装 curl请使用以下命令
```
sudo apt install curl
```
#### 使用 curl 下载文件或网页
如果你在使用 curl 命令时没有在 URL 中带任何选项,它就会读取文件并打印在终端上。
要在 Linux 终端中使用 curl 命令下载文件,你必须使用 -O大写字母 O选项
```
curl -O URL
```
![][11]
在 Linux 中,用 curl 下载多个文件是比较简单的。你只需要指定多个 URL 即可:
```
curl -O URL1 URL2 URL3
```
请记住curl 不像 wget 那么简单。当 wget 将网页保存为 index.html 时curl 会抱怨远程文件没有网页的名字。你必须按照下一节的描述用一个自定义的名字来保存它。
#### 用不同的名字下载文件
这可能会让人感到困惑,但如果要为下载的文件提供一个自定义的名称(而不是原始名称),你必须使用 -o小写 O选项
```
curl -o filename URL
```
![][12]
有些时候curl 并不能像你期望的那样下载文件,你必须使用选项 -L代表位置来正确下载。这是因为有些时候链接会重定向到其他链接而使用选项 -L它就会跟随最终的链接。
#### 用 curl 暂停和恢复下载
和 wget 一样,你也可以用 curl 的 -c 选项恢复暂停的下载:
```
curl -c URL
```
**总结**
和以往一样,在 Linux 中做同一件事有多种方法。从终端下载文件也不例外。
wget 和 curl 只是 Linux 中最流行的两个下载文件的命令。还有更多这样的命令行工具。基于终端的网络浏览器,如 [elinks][13]、[w3m][14] 等也可以用于在命令行下载文件。
就个人而言,对于一个简单的下载,我更喜欢使用 wget 而不是 curl。它更简单也不会让你感到困惑因为你可能很难理解为什么 curl 不能以预期的格式下载文件。
欢迎你的反馈和建议。
--------------------------------------------------------------------------------
via: https://itsfoss.com/download-files-from-linux-terminal/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/Download-Files-from-Linux-terminal.png?resize=800%2C450&ssl=1
[2]: https://www.gnu.org/software/wget/
[3]: https://itsfoss.com/install-latest-uget-ubuntu-linux-mint/
[4]: https://itsfoss.com/apt-command-guide/
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-file-in-linux-terminal-using-wget.png?resize=795%2C418&ssl=1
[6]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-file-in-linux-terminal-using-wget-2.png?resize=795%2C418&ssl=1
[7]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-entire-website-using-wget.png?resize=795%2C418&ssl=1
[8]: https://curl.haxx.se/
[9]: https://linuxhandbook.com/curl-command-examples/
[10]: https://itsfoss.com/install-curl-ubuntu/
[11]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-files-in-linux-using-curl.png?resize=795%2C418&ssl=1
[12]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/download-files-in-linux-using-curl-1.png?resize=795%2C418&ssl=1
[13]: http://elinks.or.cz/
[14]: http://w3m.sourceforge.net/